001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.sanitizer.Sanitizer;
032    import com.liferay.portal.kernel.sanitizer.SanitizerException;
033    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
034    import com.liferay.portal.kernel.util.ContentTypes;
035    import com.liferay.portal.kernel.util.GetterUtil;
036    import com.liferay.portal.kernel.util.InstanceFactory;
037    import com.liferay.portal.kernel.util.OrderByComparator;
038    import com.liferay.portal.kernel.util.StringBundler;
039    import com.liferay.portal.kernel.util.StringPool;
040    import com.liferay.portal.kernel.util.StringUtil;
041    import com.liferay.portal.kernel.util.Validator;
042    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
043    import com.liferay.portal.model.CacheModel;
044    import com.liferay.portal.model.ModelListener;
045    import com.liferay.portal.security.auth.PrincipalThreadLocal;
046    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
047    import com.liferay.portal.service.persistence.BatchSessionUtil;
048    import com.liferay.portal.service.persistence.CompanyPersistence;
049    import com.liferay.portal.service.persistence.GroupPersistence;
050    import com.liferay.portal.service.persistence.LockPersistence;
051    import com.liferay.portal.service.persistence.PortletPreferencesPersistence;
052    import com.liferay.portal.service.persistence.ResourcePersistence;
053    import com.liferay.portal.service.persistence.SubscriptionPersistence;
054    import com.liferay.portal.service.persistence.UserPersistence;
055    import com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence;
056    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
057    
058    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
059    import com.liferay.portlet.asset.service.persistence.AssetLinkPersistence;
060    import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
061    import com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence;
062    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
063    import com.liferay.portlet.messageboards.NoSuchMessageException;
064    import com.liferay.portlet.messageboards.model.MBMessage;
065    import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
066    import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
067    import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
068    import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
069    import com.liferay.portlet.wiki.service.persistence.WikiPagePersistence;
070    
071    import java.io.Serializable;
072    
073    import java.util.ArrayList;
074    import java.util.Collections;
075    import java.util.List;
076    
077    /**
078     * The persistence implementation for the message-boards message service.
079     *
080     * <p>
081     * Caching information and settings can be found in <code>portal.properties</code>
082     * </p>
083     *
084     * @author Brian Wing Shun Chan
085     * @see MBMessagePersistence
086     * @see MBMessageUtil
087     * @generated
088     */
089    public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
090            implements MBMessagePersistence {
091            /*
092             * NOTE FOR DEVELOPERS:
093             *
094             * 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.
095             */
096            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
097            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
098                    ".List1";
099            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
100                    ".List2";
101            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
102                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
103                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
104                            new String[] {
105                                    String.class.getName(),
106                                    
107                            "java.lang.Integer", "java.lang.Integer",
108                                    "com.liferay.portal.kernel.util.OrderByComparator"
109                            });
110            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
111                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
112                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
113                            new String[] { String.class.getName() },
114                            MBMessageModelImpl.UUID_COLUMN_BITMASK);
115            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
116                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
117                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
118                            new String[] { String.class.getName() });
119            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
120                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
121                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
122                            new String[] { String.class.getName(), Long.class.getName() },
123                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
124                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
125            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
126                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
127                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
128                            new String[] { String.class.getName(), Long.class.getName() });
129            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
130                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
131                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
132                            new String[] {
133                                    Long.class.getName(),
134                                    
135                            "java.lang.Integer", "java.lang.Integer",
136                                    "com.liferay.portal.kernel.util.OrderByComparator"
137                            });
138            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
139                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
140                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
141                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
142                            new String[] { Long.class.getName() },
143                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
144            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
145                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
146                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
147                            new String[] { Long.class.getName() });
148            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
149                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
150                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
151                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
152                            new String[] {
153                                    Long.class.getName(),
154                                    
155                            "java.lang.Integer", "java.lang.Integer",
156                                    "com.liferay.portal.kernel.util.OrderByComparator"
157                            });
158            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
159                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
160                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
161                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
162                            new String[] { Long.class.getName() },
163                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK);
164            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
165                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
166                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
167                            new String[] { Long.class.getName() });
168            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
169                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
170                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
171                            new String[] {
172                                    Long.class.getName(),
173                                    
174                            "java.lang.Integer", "java.lang.Integer",
175                                    "com.liferay.portal.kernel.util.OrderByComparator"
176                            });
177            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
178                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
179                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
180                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
181                            new String[] { Long.class.getName() },
182                            MBMessageModelImpl.THREADID_COLUMN_BITMASK);
183            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
184                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
185                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
186                            new String[] { Long.class.getName() });
187            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
188                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
189                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
190                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
191                            new String[] {
192                                    Long.class.getName(),
193                                    
194                            "java.lang.Integer", "java.lang.Integer",
195                                    "com.liferay.portal.kernel.util.OrderByComparator"
196                            });
197            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES =
198                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
199                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
200                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
201                            new String[] { Long.class.getName() },
202                            MBMessageModelImpl.THREADID_COLUMN_BITMASK);
203            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
204                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
205                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
206                            new String[] { Long.class.getName() });
207            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
208                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
209                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
210                            new String[] {
211                                    Long.class.getName(),
212                                    
213                            "java.lang.Integer", "java.lang.Integer",
214                                    "com.liferay.portal.kernel.util.OrderByComparator"
215                            });
216            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
217                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
218                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
219                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
220                            new String[] { Long.class.getName() },
221                            MBMessageModelImpl.USERID_COLUMN_BITMASK);
222            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
223                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
224                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
225                            new String[] { Long.class.getName() });
226            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
227                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
228                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
229                            new String[] {
230                                    Long.class.getName(), Long.class.getName(),
231                                    
232                            "java.lang.Integer", "java.lang.Integer",
233                                    "com.liferay.portal.kernel.util.OrderByComparator"
234                            });
235            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
236                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
237                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
238                            new String[] { Long.class.getName(), Long.class.getName() },
239                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
240                            MBMessageModelImpl.USERID_COLUMN_BITMASK);
241            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
242                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
243                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
244                            new String[] { Long.class.getName(), Long.class.getName() });
245            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
246                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
247                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
248                            new String[] {
249                                    Long.class.getName(), Long.class.getName(),
250                                    
251                            "java.lang.Integer", "java.lang.Integer",
252                                    "com.liferay.portal.kernel.util.OrderByComparator"
253                            });
254            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
255                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
256                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
257                            new String[] { Long.class.getName(), Long.class.getName() },
258                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
259                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK);
260            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
261                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
262                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
263                            new String[] { Long.class.getName(), Long.class.getName() });
264            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
265                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
266                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
267                            new String[] {
268                                    Long.class.getName(), Integer.class.getName(),
269                                    
270                            "java.lang.Integer", "java.lang.Integer",
271                                    "com.liferay.portal.kernel.util.OrderByComparator"
272                            });
273            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
274                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
275                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
276                            new String[] { Long.class.getName(), Integer.class.getName() },
277                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
278                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
279            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
280                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
281                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
282                            new String[] { Long.class.getName(), Integer.class.getName() });
283            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
284                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
285                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
286                            new String[] {
287                                    Long.class.getName(), Integer.class.getName(),
288                                    
289                            "java.lang.Integer", "java.lang.Integer",
290                                    "com.liferay.portal.kernel.util.OrderByComparator"
291                            });
292            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
293                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
294                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
295                            new String[] { Long.class.getName(), Integer.class.getName() },
296                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
297                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
298            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
299                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
300                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
301                            new String[] { Long.class.getName(), Integer.class.getName() });
302            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
303                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
304                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
305                            new String[] {
306                                    Long.class.getName(), Long.class.getName(),
307                                    
308                            "java.lang.Integer", "java.lang.Integer",
309                                    "com.liferay.portal.kernel.util.OrderByComparator"
310                            });
311            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
312                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
313                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
314                            new String[] { Long.class.getName(), Long.class.getName() },
315                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
316                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK);
317            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
318                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
319                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
320                            new String[] { Long.class.getName(), Long.class.getName() });
321            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
322                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
323                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
324                            new String[] {
325                                    Long.class.getName(), Long.class.getName(),
326                                    
327                            "java.lang.Integer", "java.lang.Integer",
328                                    "com.liferay.portal.kernel.util.OrderByComparator"
329                            });
330            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
331                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
332                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
333                            new String[] { Long.class.getName(), Long.class.getName() },
334                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
335                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK);
336            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
337                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
338                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
339                            new String[] { Long.class.getName(), Long.class.getName() });
340            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
341                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
342                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
343                            new String[] {
344                                    Long.class.getName(), Long.class.getName(),
345                                    
346                            "java.lang.Integer", "java.lang.Integer",
347                                    "com.liferay.portal.kernel.util.OrderByComparator"
348                            });
349            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
350                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
351                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
352                            new String[] { Long.class.getName(), Long.class.getName() },
353                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
354                            MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK);
355            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
356                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
357                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
358                            new String[] { Long.class.getName(), Long.class.getName() });
359            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
360                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
361                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
362                            new String[] {
363                                    Long.class.getName(), Boolean.class.getName(),
364                                    
365                            "java.lang.Integer", "java.lang.Integer",
366                                    "com.liferay.portal.kernel.util.OrderByComparator"
367                            });
368            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
369                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
370                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
371                            new String[] { Long.class.getName(), Boolean.class.getName() },
372                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
373                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK);
374            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
375                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
376                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
377                            new String[] { Long.class.getName(), Boolean.class.getName() });
378            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
379                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
380                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
381                            new String[] {
382                                    Long.class.getName(), Integer.class.getName(),
383                                    
384                            "java.lang.Integer", "java.lang.Integer",
385                                    "com.liferay.portal.kernel.util.OrderByComparator"
386                            });
387            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
388                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
389                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
390                            new String[] { Long.class.getName(), Integer.class.getName() },
391                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
392                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
393            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
394                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
395                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
396                            new String[] { Long.class.getName(), Integer.class.getName() });
397            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
398                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
399                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
400                            new String[] {
401                                    Long.class.getName(), Integer.class.getName(),
402                                    
403                            "java.lang.Integer", "java.lang.Integer",
404                                    "com.liferay.portal.kernel.util.OrderByComparator"
405                            });
406            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
407                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
408                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
409                            new String[] { Long.class.getName(), Integer.class.getName() },
410                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
411                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
412            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
413                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
414                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
415                            new String[] { Long.class.getName(), Integer.class.getName() });
416            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
417                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
418                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
419                            new String[] {
420                                    Long.class.getName(), Long.class.getName(),
421                                    Integer.class.getName(),
422                                    
423                            "java.lang.Integer", "java.lang.Integer",
424                                    "com.liferay.portal.kernel.util.OrderByComparator"
425                            });
426            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
427                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
428                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
429                            new String[] {
430                                    Long.class.getName(), Long.class.getName(),
431                                    Integer.class.getName()
432                            },
433                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
434                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
435                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
436            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
437                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
438                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
439                            new String[] {
440                                    Long.class.getName(), Long.class.getName(),
441                                    Integer.class.getName()
442                            });
443            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
444                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
445                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
446                            new String[] {
447                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
448                                    
449                            "java.lang.Integer", "java.lang.Integer",
450                                    "com.liferay.portal.kernel.util.OrderByComparator"
451                            });
452            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
453                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
454                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
455                            new String[] {
456                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
457                            },
458                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
459                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
460                            MBMessageModelImpl.THREADID_COLUMN_BITMASK);
461            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
462                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
463                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
464                            new String[] {
465                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
466                            });
467            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
468                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
469                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
470                            new String[] {
471                                    Long.class.getName(), Long.class.getName(),
472                                    Integer.class.getName(),
473                                    
474                            "java.lang.Integer", "java.lang.Integer",
475                                    "com.liferay.portal.kernel.util.OrderByComparator"
476                            });
477            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
478                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
479                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
480                            new String[] {
481                                    Long.class.getName(), Long.class.getName(),
482                                    Integer.class.getName()
483                            },
484                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
485                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
486                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
487            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
488                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
489                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
490                            new String[] {
491                                    Long.class.getName(), Long.class.getName(),
492                                    Integer.class.getName()
493                            });
494            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
495                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
496                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
497                            new String[] {
498                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
499                                    
500                            "java.lang.Integer", "java.lang.Integer",
501                                    "com.liferay.portal.kernel.util.OrderByComparator"
502                            });
503            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
504                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
505                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
506                            new String[] {
507                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
508                            },
509                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
510                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
511                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK);
512            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
513                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
514                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
515                            new String[] {
516                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
517                            });
518            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
519                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
520                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
521                            new String[] {
522                                    Long.class.getName(), Long.class.getName(),
523                                    Integer.class.getName(),
524                                    
525                            "java.lang.Integer", "java.lang.Integer",
526                                    "com.liferay.portal.kernel.util.OrderByComparator"
527                            });
528            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
529                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
530                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
531                            new String[] {
532                                    Long.class.getName(), Long.class.getName(),
533                                    Integer.class.getName()
534                            },
535                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
536                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
537                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
538            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
539                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
540                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
541                            new String[] {
542                                    Long.class.getName(), Long.class.getName(),
543                                    Integer.class.getName()
544                            });
545            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
546                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
547                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
548                            new String[] {
549                                    Long.class.getName(), Long.class.getName(),
550                                    Integer.class.getName(),
551                                    
552                            "java.lang.Integer", "java.lang.Integer",
553                                    "com.liferay.portal.kernel.util.OrderByComparator"
554                            });
555            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
556                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
557                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
558                            new String[] {
559                                    Long.class.getName(), Long.class.getName(),
560                                    Integer.class.getName()
561                            },
562                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
563                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
564                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
565            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
566                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
567                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
568                            new String[] {
569                                    Long.class.getName(), Long.class.getName(),
570                                    Integer.class.getName()
571                            });
572            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
573                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
574                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
575                            new String[] {
576                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
577                                    Boolean.class.getName(),
578                                    
579                            "java.lang.Integer", "java.lang.Integer",
580                                    "com.liferay.portal.kernel.util.OrderByComparator"
581                            });
582            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
583                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
584                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
585                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
586                            new String[] {
587                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
588                                    Boolean.class.getName()
589                            },
590                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
591                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
592                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
593                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK);
594            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
595                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
596                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
597                            new String[] {
598                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
599                                    Boolean.class.getName()
600                            });
601            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
602                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
603                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
604                            new String[] {
605                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
606                                    Integer.class.getName(),
607                                    
608                            "java.lang.Integer", "java.lang.Integer",
609                                    "com.liferay.portal.kernel.util.OrderByComparator"
610                            });
611            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
612                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
613                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
614                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
615                            new String[] {
616                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
617                                    Integer.class.getName()
618                            },
619                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
620                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
621                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
622                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
623            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
624                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
625                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
626                            new String[] {
627                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
628                                    Integer.class.getName()
629                            });
630            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
631                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
632                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
633                            new String[] {
634                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
635                                    Integer.class.getName(),
636                                    
637                            "java.lang.Integer", "java.lang.Integer",
638                                    "com.liferay.portal.kernel.util.OrderByComparator"
639                            });
640            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
641                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
642                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
643                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
644                            new String[] {
645                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
646                                    Integer.class.getName()
647                            },
648                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
649                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
650                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
651                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
652            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
653                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
654                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
655                            new String[] {
656                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
657                                    Integer.class.getName()
658                            });
659            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
660                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
661                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
662            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
663                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
664                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
665            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
666                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
667                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
668    
669            /**
670             * Caches the message-boards message in the entity cache if it is enabled.
671             *
672             * @param mbMessage the message-boards message
673             */
674            public void cacheResult(MBMessage mbMessage) {
675                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
676                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
677    
678                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
679                            new Object[] {
680                                    mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
681                            }, mbMessage);
682    
683                    mbMessage.resetOriginalValues();
684            }
685    
686            /**
687             * Caches the message-boards messages in the entity cache if it is enabled.
688             *
689             * @param mbMessages the message-boards messages
690             */
691            public void cacheResult(List<MBMessage> mbMessages) {
692                    for (MBMessage mbMessage : mbMessages) {
693                            if (EntityCacheUtil.getResult(
694                                                    MBMessageModelImpl.ENTITY_CACHE_ENABLED,
695                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
696                                    cacheResult(mbMessage);
697                            }
698                            else {
699                                    mbMessage.resetOriginalValues();
700                            }
701                    }
702            }
703    
704            /**
705             * Clears the cache for all message-boards messages.
706             *
707             * <p>
708             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
709             * </p>
710             */
711            @Override
712            public void clearCache() {
713                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
714                            CacheRegistryUtil.clear(MBMessageImpl.class.getName());
715                    }
716    
717                    EntityCacheUtil.clearCache(MBMessageImpl.class.getName());
718    
719                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
720                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
721                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
722            }
723    
724            /**
725             * Clears the cache for the message-boards message.
726             *
727             * <p>
728             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
729             * </p>
730             */
731            @Override
732            public void clearCache(MBMessage mbMessage) {
733                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
734                            MBMessageImpl.class, mbMessage.getPrimaryKey());
735    
736                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
737                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
738    
739                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
740                            new Object[] {
741                                    mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
742                            });
743            }
744    
745            /**
746             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
747             *
748             * @param messageId the primary key for the new message-boards message
749             * @return the new message-boards message
750             */
751            public MBMessage create(long messageId) {
752                    MBMessage mbMessage = new MBMessageImpl();
753    
754                    mbMessage.setNew(true);
755                    mbMessage.setPrimaryKey(messageId);
756    
757                    String uuid = PortalUUIDUtil.generate();
758    
759                    mbMessage.setUuid(uuid);
760    
761                    return mbMessage;
762            }
763    
764            /**
765             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
766             *
767             * @param primaryKey the primary key of the message-boards message
768             * @return the message-boards message that was removed
769             * @throws com.liferay.portal.NoSuchModelException if a message-boards message with the primary key could not be found
770             * @throws SystemException if a system exception occurred
771             */
772            @Override
773            public MBMessage remove(Serializable primaryKey)
774                    throws NoSuchModelException, SystemException {
775                    return remove(((Long)primaryKey).longValue());
776            }
777    
778            /**
779             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
780             *
781             * @param messageId the primary key of the message-boards message
782             * @return the message-boards message that was removed
783             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
784             * @throws SystemException if a system exception occurred
785             */
786            public MBMessage remove(long messageId)
787                    throws NoSuchMessageException, SystemException {
788                    Session session = null;
789    
790                    try {
791                            session = openSession();
792    
793                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
794                                            Long.valueOf(messageId));
795    
796                            if (mbMessage == null) {
797                                    if (_log.isWarnEnabled()) {
798                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageId);
799                                    }
800    
801                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
802                                            messageId);
803                            }
804    
805                            return mbMessagePersistence.remove(mbMessage);
806                    }
807                    catch (NoSuchMessageException nsee) {
808                            throw nsee;
809                    }
810                    catch (Exception e) {
811                            throw processException(e);
812                    }
813                    finally {
814                            closeSession(session);
815                    }
816            }
817    
818            /**
819             * Removes the message-boards message from the database. Also notifies the appropriate model listeners.
820             *
821             * @param mbMessage the message-boards message
822             * @return the message-boards message that was removed
823             * @throws SystemException if a system exception occurred
824             */
825            @Override
826            public MBMessage remove(MBMessage mbMessage) throws SystemException {
827                    return super.remove(mbMessage);
828            }
829    
830            @Override
831            protected MBMessage removeImpl(MBMessage mbMessage)
832                    throws SystemException {
833                    mbMessage = toUnwrappedModel(mbMessage);
834    
835                    Session session = null;
836    
837                    try {
838                            session = openSession();
839    
840                            BatchSessionUtil.delete(session, mbMessage);
841                    }
842                    catch (Exception e) {
843                            throw processException(e);
844                    }
845                    finally {
846                            closeSession(session);
847                    }
848    
849                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
850                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
851    
852                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
853    
854                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
855                            new Object[] {
856                                    mbMessageModelImpl.getUuid(),
857                                    Long.valueOf(mbMessageModelImpl.getGroupId())
858                            });
859    
860                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
861                            MBMessageImpl.class, mbMessage.getPrimaryKey());
862    
863                    return mbMessage;
864            }
865    
866            @Override
867            public MBMessage updateImpl(
868                    com.liferay.portlet.messageboards.model.MBMessage mbMessage,
869                    boolean merge) throws SystemException {
870                    mbMessage = toUnwrappedModel(mbMessage);
871    
872                    boolean isNew = mbMessage.isNew();
873    
874                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
875    
876                    if (Validator.isNull(mbMessage.getUuid())) {
877                            String uuid = PortalUUIDUtil.generate();
878    
879                            mbMessage.setUuid(uuid);
880                    }
881    
882                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
883    
884                    if (userId > 0) {
885                            long companyId = mbMessage.getCompanyId();
886    
887                            long groupId = mbMessage.getGroupId();
888    
889                            long messageId = 0;
890    
891                            if (!isNew) {
892                                    messageId = mbMessage.getPrimaryKey();
893                            }
894    
895                            try {
896                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
897                                                    userId,
898                                                    com.liferay.portlet.messageboards.model.MBMessage.class.getName(),
899                                                    messageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
900                                                    mbMessage.getSubject(), null));
901                            }
902                            catch (SanitizerException se) {
903                                    throw new SystemException(se);
904                            }
905                    }
906    
907                    Session session = null;
908    
909                    try {
910                            session = openSession();
911    
912                            BatchSessionUtil.update(session, mbMessage, merge);
913    
914                            mbMessage.setNew(false);
915                    }
916                    catch (Exception e) {
917                            throw processException(e);
918                    }
919                    finally {
920                            closeSession(session);
921                    }
922    
923                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
924    
925                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
926                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
927                    }
928    
929                    else {
930                            if ((mbMessageModelImpl.getColumnBitmask() &
931                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
932                                    Object[] args = new Object[] {
933                                                    mbMessageModelImpl.getOriginalUuid()
934                                            };
935    
936                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
937                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
938                                            args);
939    
940                                    args = new Object[] { mbMessageModelImpl.getUuid() };
941    
942                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
943                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
944                                            args);
945                            }
946    
947                            if ((mbMessageModelImpl.getColumnBitmask() &
948                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
949                                    Object[] args = new Object[] {
950                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId())
951                                            };
952    
953                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
954                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
955                                            args);
956    
957                                    args = new Object[] {
958                                                    Long.valueOf(mbMessageModelImpl.getGroupId())
959                                            };
960    
961                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
962                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
963                                            args);
964                            }
965    
966                            if ((mbMessageModelImpl.getColumnBitmask() &
967                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
968                                    Object[] args = new Object[] {
969                                                    Long.valueOf(mbMessageModelImpl.getOriginalCompanyId())
970                                            };
971    
972                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
973                                            args);
974                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
975                                            args);
976    
977                                    args = new Object[] {
978                                                    Long.valueOf(mbMessageModelImpl.getCompanyId())
979                                            };
980    
981                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
982                                            args);
983                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
984                                            args);
985                            }
986    
987                            if ((mbMessageModelImpl.getColumnBitmask() &
988                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
989                                    Object[] args = new Object[] {
990                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
991                                            };
992    
993                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
994                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
995                                            args);
996    
997                                    args = new Object[] {
998                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
999                                            };
1000    
1001                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
1002                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
1003                                            args);
1004                            }
1005    
1006                            if ((mbMessageModelImpl.getColumnBitmask() &
1007                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
1008                                    Object[] args = new Object[] {
1009                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
1010                                            };
1011    
1012                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
1013                                            args);
1014                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
1015                                            args);
1016    
1017                                    args = new Object[] {
1018                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
1019                                            };
1020    
1021                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
1022                                            args);
1023                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
1024                                            args);
1025                            }
1026    
1027                            if ((mbMessageModelImpl.getColumnBitmask() &
1028                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1029                                    Object[] args = new Object[] {
1030                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId())
1031                                            };
1032    
1033                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1034                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1035                                            args);
1036    
1037                                    args = new Object[] { Long.valueOf(mbMessageModelImpl.getUserId()) };
1038    
1039                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1040                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1041                                            args);
1042                            }
1043    
1044                            if ((mbMessageModelImpl.getColumnBitmask() &
1045                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
1046                                    Object[] args = new Object[] {
1047                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1048                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId())
1049                                            };
1050    
1051                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
1052                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
1053                                            args);
1054    
1055                                    args = new Object[] {
1056                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1057                                                    Long.valueOf(mbMessageModelImpl.getUserId())
1058                                            };
1059    
1060                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
1061                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
1062                                            args);
1063                            }
1064    
1065                            if ((mbMessageModelImpl.getColumnBitmask() &
1066                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
1067                                    Object[] args = new Object[] {
1068                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1069                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId())
1070                                            };
1071    
1072                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
1073                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
1074                                            args);
1075    
1076                                    args = new Object[] {
1077                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1078                                                    Long.valueOf(mbMessageModelImpl.getCategoryId())
1079                                            };
1080    
1081                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
1082                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
1083                                            args);
1084                            }
1085    
1086                            if ((mbMessageModelImpl.getColumnBitmask() &
1087                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
1088                                    Object[] args = new Object[] {
1089                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1090                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1091                                            };
1092    
1093                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
1094                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
1095                                            args);
1096    
1097                                    args = new Object[] {
1098                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1099                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1100                                            };
1101    
1102                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
1103                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
1104                                            args);
1105                            }
1106    
1107                            if ((mbMessageModelImpl.getColumnBitmask() &
1108                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
1109                                    Object[] args = new Object[] {
1110                                                    Long.valueOf(mbMessageModelImpl.getOriginalCompanyId()),
1111                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1112                                            };
1113    
1114                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
1115                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
1116                                            args);
1117    
1118                                    args = new Object[] {
1119                                                    Long.valueOf(mbMessageModelImpl.getCompanyId()),
1120                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1121                                            };
1122    
1123                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
1124                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
1125                                            args);
1126                            }
1127    
1128                            if ((mbMessageModelImpl.getColumnBitmask() &
1129                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
1130                                    Object[] args = new Object[] {
1131                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1132                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId())
1133                                            };
1134    
1135                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
1136                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
1137                                            args);
1138    
1139                                    args = new Object[] {
1140                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1141                                                    Long.valueOf(mbMessageModelImpl.getClassNameId())
1142                                            };
1143    
1144                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
1145                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
1146                                            args);
1147                            }
1148    
1149                            if ((mbMessageModelImpl.getColumnBitmask() &
1150                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
1151                                    Object[] args = new Object[] {
1152                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1153                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK())
1154                                            };
1155    
1156                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1157                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1158                                            args);
1159    
1160                                    args = new Object[] {
1161                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1162                                                    Long.valueOf(mbMessageModelImpl.getClassPK())
1163                                            };
1164    
1165                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1166                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1167                                            args);
1168                            }
1169    
1170                            if ((mbMessageModelImpl.getColumnBitmask() &
1171                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
1172                                    Object[] args = new Object[] {
1173                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1174                                                    Long.valueOf(mbMessageModelImpl.getOriginalParentMessageId())
1175                                            };
1176    
1177                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
1178                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
1179                                            args);
1180    
1181                                    args = new Object[] {
1182                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1183                                                    Long.valueOf(mbMessageModelImpl.getParentMessageId())
1184                                            };
1185    
1186                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
1187                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
1188                                            args);
1189                            }
1190    
1191                            if ((mbMessageModelImpl.getColumnBitmask() &
1192                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
1193                                    Object[] args = new Object[] {
1194                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1195                                                    Boolean.valueOf(mbMessageModelImpl.getOriginalAnswer())
1196                                            };
1197    
1198                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
1199                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
1200                                            args);
1201    
1202                                    args = new Object[] {
1203                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1204                                                    Boolean.valueOf(mbMessageModelImpl.getAnswer())
1205                                            };
1206    
1207                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
1208                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
1209                                            args);
1210                            }
1211    
1212                            if ((mbMessageModelImpl.getColumnBitmask() &
1213                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
1214                                    Object[] args = new Object[] {
1215                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1216                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1217                                            };
1218    
1219                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
1220                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
1221                                            args);
1222    
1223                                    args = new Object[] {
1224                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1225                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1226                                            };
1227    
1228                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
1229                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
1230                                            args);
1231                            }
1232    
1233                            if ((mbMessageModelImpl.getColumnBitmask() &
1234                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
1235                                    Object[] args = new Object[] {
1236                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1237                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1238                                            };
1239    
1240                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
1241                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
1242                                            args);
1243    
1244                                    args = new Object[] {
1245                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1246                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1247                                            };
1248    
1249                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
1250                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
1251                                            args);
1252                            }
1253    
1254                            if ((mbMessageModelImpl.getColumnBitmask() &
1255                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
1256                                    Object[] args = new Object[] {
1257                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1258                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1259                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1260                                            };
1261    
1262                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
1263                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
1264                                            args);
1265    
1266                                    args = new Object[] {
1267                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1268                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1269                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1270                                            };
1271    
1272                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
1273                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
1274                                            args);
1275                            }
1276    
1277                            if ((mbMessageModelImpl.getColumnBitmask() &
1278                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
1279                                    Object[] args = new Object[] {
1280                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1281                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1282                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
1283                                            };
1284    
1285                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
1286                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
1287                                            args);
1288    
1289                                    args = new Object[] {
1290                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1291                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1292                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
1293                                            };
1294    
1295                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
1296                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
1297                                            args);
1298                            }
1299    
1300                            if ((mbMessageModelImpl.getColumnBitmask() &
1301                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
1302                                    Object[] args = new Object[] {
1303                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1304                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1305                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1306                                            };
1307    
1308                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
1309                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
1310                                            args);
1311    
1312                                    args = new Object[] {
1313                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1314                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1315                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1316                                            };
1317    
1318                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
1319                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
1320                                            args);
1321                            }
1322    
1323                            if ((mbMessageModelImpl.getColumnBitmask() &
1324                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
1325                                    Object[] args = new Object[] {
1326                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1327                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1328                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK())
1329                                            };
1330    
1331                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
1332                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
1333                                            args);
1334    
1335                                    args = new Object[] {
1336                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1337                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1338                                                    Long.valueOf(mbMessageModelImpl.getClassPK())
1339                                            };
1340    
1341                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
1342                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
1343                                            args);
1344                            }
1345    
1346                            if ((mbMessageModelImpl.getColumnBitmask() &
1347                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
1348                                    Object[] args = new Object[] {
1349                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1350                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1351                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1352                                            };
1353    
1354                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
1355                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
1356                                            args);
1357    
1358                                    args = new Object[] {
1359                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1360                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1361                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1362                                            };
1363    
1364                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
1365                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
1366                                            args);
1367                            }
1368    
1369                            if ((mbMessageModelImpl.getColumnBitmask() &
1370                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
1371                                    Object[] args = new Object[] {
1372                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1373                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK()),
1374                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1375                                            };
1376    
1377                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
1378                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
1379                                            args);
1380    
1381                                    args = new Object[] {
1382                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1383                                                    Long.valueOf(mbMessageModelImpl.getClassPK()),
1384                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1385                                            };
1386    
1387                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
1388                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
1389                                            args);
1390                            }
1391    
1392                            if ((mbMessageModelImpl.getColumnBitmask() &
1393                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
1394                                    Object[] args = new Object[] {
1395                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1396                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1397                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1398                                                    Boolean.valueOf(mbMessageModelImpl.getOriginalAnswer())
1399                                            };
1400    
1401                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
1402                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
1403                                            args);
1404    
1405                                    args = new Object[] {
1406                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1407                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1408                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1409                                                    Boolean.valueOf(mbMessageModelImpl.getAnswer())
1410                                            };
1411    
1412                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
1413                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
1414                                            args);
1415                            }
1416    
1417                            if ((mbMessageModelImpl.getColumnBitmask() &
1418                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
1419                                    Object[] args = new Object[] {
1420                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1421                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1422                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1423                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1424                                            };
1425    
1426                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
1427                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
1428                                            args);
1429    
1430                                    args = new Object[] {
1431                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1432                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1433                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1434                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1435                                            };
1436    
1437                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
1438                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
1439                                            args);
1440                            }
1441    
1442                            if ((mbMessageModelImpl.getColumnBitmask() &
1443                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
1444                                    Object[] args = new Object[] {
1445                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1446                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1447                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK()),
1448                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1449                                            };
1450    
1451                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
1452                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
1453                                            args);
1454    
1455                                    args = new Object[] {
1456                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1457                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1458                                                    Long.valueOf(mbMessageModelImpl.getClassPK()),
1459                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1460                                            };
1461    
1462                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
1463                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
1464                                            args);
1465                            }
1466                    }
1467    
1468                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1469                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
1470    
1471                    if (isNew) {
1472                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1473                                    new Object[] {
1474                                            mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
1475                                    }, mbMessage);
1476                    }
1477                    else {
1478                            if ((mbMessageModelImpl.getColumnBitmask() &
1479                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
1480                                    Object[] args = new Object[] {
1481                                                    mbMessageModelImpl.getOriginalUuid(),
1482                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId())
1483                                            };
1484    
1485                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
1486                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
1487    
1488                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1489                                            new Object[] {
1490                                                    mbMessage.getUuid(),
1491                                                    Long.valueOf(mbMessage.getGroupId())
1492                                            }, mbMessage);
1493                            }
1494                    }
1495    
1496                    return mbMessage;
1497            }
1498    
1499            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
1500                    if (mbMessage instanceof MBMessageImpl) {
1501                            return mbMessage;
1502                    }
1503    
1504                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
1505    
1506                    mbMessageImpl.setNew(mbMessage.isNew());
1507                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
1508    
1509                    mbMessageImpl.setUuid(mbMessage.getUuid());
1510                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
1511                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
1512                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
1513                    mbMessageImpl.setUserId(mbMessage.getUserId());
1514                    mbMessageImpl.setUserName(mbMessage.getUserName());
1515                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
1516                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
1517                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
1518                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
1519                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
1520                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
1521                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
1522                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
1523                    mbMessageImpl.setSubject(mbMessage.getSubject());
1524                    mbMessageImpl.setBody(mbMessage.getBody());
1525                    mbMessageImpl.setFormat(mbMessage.getFormat());
1526                    mbMessageImpl.setAttachments(mbMessage.isAttachments());
1527                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
1528                    mbMessageImpl.setPriority(mbMessage.getPriority());
1529                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
1530                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
1531                    mbMessageImpl.setStatus(mbMessage.getStatus());
1532                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
1533                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
1534                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
1535    
1536                    return mbMessageImpl;
1537            }
1538    
1539            /**
1540             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1541             *
1542             * @param primaryKey the primary key of the message-boards message
1543             * @return the message-boards message
1544             * @throws com.liferay.portal.NoSuchModelException if a message-boards message with the primary key could not be found
1545             * @throws SystemException if a system exception occurred
1546             */
1547            @Override
1548            public MBMessage findByPrimaryKey(Serializable primaryKey)
1549                    throws NoSuchModelException, SystemException {
1550                    return findByPrimaryKey(((Long)primaryKey).longValue());
1551            }
1552    
1553            /**
1554             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchMessageException} if it could not be found.
1555             *
1556             * @param messageId the primary key of the message-boards message
1557             * @return the message-boards message
1558             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1559             * @throws SystemException if a system exception occurred
1560             */
1561            public MBMessage findByPrimaryKey(long messageId)
1562                    throws NoSuchMessageException, SystemException {
1563                    MBMessage mbMessage = fetchByPrimaryKey(messageId);
1564    
1565                    if (mbMessage == null) {
1566                            if (_log.isWarnEnabled()) {
1567                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageId);
1568                            }
1569    
1570                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1571                                    messageId);
1572                    }
1573    
1574                    return mbMessage;
1575            }
1576    
1577            /**
1578             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
1579             *
1580             * @param primaryKey the primary key of the message-boards message
1581             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
1582             * @throws SystemException if a system exception occurred
1583             */
1584            @Override
1585            public MBMessage fetchByPrimaryKey(Serializable primaryKey)
1586                    throws SystemException {
1587                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
1588            }
1589    
1590            /**
1591             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
1592             *
1593             * @param messageId the primary key of the message-boards message
1594             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
1595             * @throws SystemException if a system exception occurred
1596             */
1597            public MBMessage fetchByPrimaryKey(long messageId)
1598                    throws SystemException {
1599                    MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1600                                    MBMessageImpl.class, messageId);
1601    
1602                    if (mbMessage == _nullMBMessage) {
1603                            return null;
1604                    }
1605    
1606                    if (mbMessage == null) {
1607                            Session session = null;
1608    
1609                            boolean hasException = false;
1610    
1611                            try {
1612                                    session = openSession();
1613    
1614                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
1615                                                    Long.valueOf(messageId));
1616                            }
1617                            catch (Exception e) {
1618                                    hasException = true;
1619    
1620                                    throw processException(e);
1621                            }
1622                            finally {
1623                                    if (mbMessage != null) {
1624                                            cacheResult(mbMessage);
1625                                    }
1626                                    else if (!hasException) {
1627                                            EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1628                                                    MBMessageImpl.class, messageId, _nullMBMessage);
1629                                    }
1630    
1631                                    closeSession(session);
1632                            }
1633                    }
1634    
1635                    return mbMessage;
1636            }
1637    
1638            /**
1639             * Returns all the message-boards messages where uuid = &#63;.
1640             *
1641             * @param uuid the uuid
1642             * @return the matching message-boards messages
1643             * @throws SystemException if a system exception occurred
1644             */
1645            public List<MBMessage> findByUuid(String uuid) throws SystemException {
1646                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1647            }
1648    
1649            /**
1650             * Returns a range of all the message-boards messages where uuid = &#63;.
1651             *
1652             * <p>
1653             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1654             * </p>
1655             *
1656             * @param uuid the uuid
1657             * @param start the lower bound of the range of message-boards messages
1658             * @param end the upper bound of the range of message-boards messages (not inclusive)
1659             * @return the range of matching message-boards messages
1660             * @throws SystemException if a system exception occurred
1661             */
1662            public List<MBMessage> findByUuid(String uuid, int start, int end)
1663                    throws SystemException {
1664                    return findByUuid(uuid, start, end, null);
1665            }
1666    
1667            /**
1668             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
1669             *
1670             * <p>
1671             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1672             * </p>
1673             *
1674             * @param uuid the uuid
1675             * @param start the lower bound of the range of message-boards messages
1676             * @param end the upper bound of the range of message-boards messages (not inclusive)
1677             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1678             * @return the ordered range of matching message-boards messages
1679             * @throws SystemException if a system exception occurred
1680             */
1681            public List<MBMessage> findByUuid(String uuid, int start, int end,
1682                    OrderByComparator orderByComparator) throws SystemException {
1683                    FinderPath finderPath = null;
1684                    Object[] finderArgs = null;
1685    
1686                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1687                                    (orderByComparator == null)) {
1688                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
1689                            finderArgs = new Object[] { uuid };
1690                    }
1691                    else {
1692                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
1693                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
1694                    }
1695    
1696                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
1697                                    finderArgs, this);
1698    
1699                    if (list == null) {
1700                            StringBundler query = null;
1701    
1702                            if (orderByComparator != null) {
1703                                    query = new StringBundler(3 +
1704                                                    (orderByComparator.getOrderByFields().length * 3));
1705                            }
1706                            else {
1707                                    query = new StringBundler(3);
1708                            }
1709    
1710                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1711    
1712                            if (uuid == null) {
1713                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1714                            }
1715                            else {
1716                                    if (uuid.equals(StringPool.BLANK)) {
1717                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1718                                    }
1719                                    else {
1720                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1721                                    }
1722                            }
1723    
1724                            if (orderByComparator != null) {
1725                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1726                                            orderByComparator);
1727                            }
1728    
1729                            else {
1730                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1731                            }
1732    
1733                            String sql = query.toString();
1734    
1735                            Session session = null;
1736    
1737                            try {
1738                                    session = openSession();
1739    
1740                                    Query q = session.createQuery(sql);
1741    
1742                                    QueryPos qPos = QueryPos.getInstance(q);
1743    
1744                                    if (uuid != null) {
1745                                            qPos.add(uuid);
1746                                    }
1747    
1748                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
1749                                                    end);
1750                            }
1751                            catch (Exception e) {
1752                                    throw processException(e);
1753                            }
1754                            finally {
1755                                    if (list == null) {
1756                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1757                                    }
1758                                    else {
1759                                            cacheResult(list);
1760    
1761                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1762                                    }
1763    
1764                                    closeSession(session);
1765                            }
1766                    }
1767    
1768                    return list;
1769            }
1770    
1771            /**
1772             * Returns the first message-boards message in the ordered set where uuid = &#63;.
1773             *
1774             * <p>
1775             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1776             * </p>
1777             *
1778             * @param uuid the uuid
1779             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1780             * @return the first matching message-boards message
1781             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1782             * @throws SystemException if a system exception occurred
1783             */
1784            public MBMessage findByUuid_First(String uuid,
1785                    OrderByComparator orderByComparator)
1786                    throws NoSuchMessageException, SystemException {
1787                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
1788    
1789                    if (list.isEmpty()) {
1790                            StringBundler msg = new StringBundler(4);
1791    
1792                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1793    
1794                            msg.append("uuid=");
1795                            msg.append(uuid);
1796    
1797                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1798    
1799                            throw new NoSuchMessageException(msg.toString());
1800                    }
1801                    else {
1802                            return list.get(0);
1803                    }
1804            }
1805    
1806            /**
1807             * Returns the last message-boards message in the ordered set where uuid = &#63;.
1808             *
1809             * <p>
1810             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1811             * </p>
1812             *
1813             * @param uuid the uuid
1814             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1815             * @return the last matching message-boards message
1816             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1817             * @throws SystemException if a system exception occurred
1818             */
1819            public MBMessage findByUuid_Last(String uuid,
1820                    OrderByComparator orderByComparator)
1821                    throws NoSuchMessageException, SystemException {
1822                    int count = countByUuid(uuid);
1823    
1824                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
1825                                    orderByComparator);
1826    
1827                    if (list.isEmpty()) {
1828                            StringBundler msg = new StringBundler(4);
1829    
1830                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1831    
1832                            msg.append("uuid=");
1833                            msg.append(uuid);
1834    
1835                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1836    
1837                            throw new NoSuchMessageException(msg.toString());
1838                    }
1839                    else {
1840                            return list.get(0);
1841                    }
1842            }
1843    
1844            /**
1845             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
1846             *
1847             * <p>
1848             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1849             * </p>
1850             *
1851             * @param messageId the primary key of the current message-boards message
1852             * @param uuid the uuid
1853             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1854             * @return the previous, current, and next message-boards message
1855             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1856             * @throws SystemException if a system exception occurred
1857             */
1858            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
1859                    OrderByComparator orderByComparator)
1860                    throws NoSuchMessageException, SystemException {
1861                    MBMessage mbMessage = findByPrimaryKey(messageId);
1862    
1863                    Session session = null;
1864    
1865                    try {
1866                            session = openSession();
1867    
1868                            MBMessage[] array = new MBMessageImpl[3];
1869    
1870                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
1871                                            orderByComparator, true);
1872    
1873                            array[1] = mbMessage;
1874    
1875                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
1876                                            orderByComparator, false);
1877    
1878                            return array;
1879                    }
1880                    catch (Exception e) {
1881                            throw processException(e);
1882                    }
1883                    finally {
1884                            closeSession(session);
1885                    }
1886            }
1887    
1888            protected MBMessage getByUuid_PrevAndNext(Session session,
1889                    MBMessage mbMessage, String uuid, OrderByComparator orderByComparator,
1890                    boolean previous) {
1891                    StringBundler query = null;
1892    
1893                    if (orderByComparator != null) {
1894                            query = new StringBundler(6 +
1895                                            (orderByComparator.getOrderByFields().length * 6));
1896                    }
1897                    else {
1898                            query = new StringBundler(3);
1899                    }
1900    
1901                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1902    
1903                    if (uuid == null) {
1904                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1905                    }
1906                    else {
1907                            if (uuid.equals(StringPool.BLANK)) {
1908                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1909                            }
1910                            else {
1911                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1912                            }
1913                    }
1914    
1915                    if (orderByComparator != null) {
1916                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1917    
1918                            if (orderByConditionFields.length > 0) {
1919                                    query.append(WHERE_AND);
1920                            }
1921    
1922                            for (int i = 0; i < orderByConditionFields.length; i++) {
1923                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1924                                    query.append(orderByConditionFields[i]);
1925    
1926                                    if ((i + 1) < orderByConditionFields.length) {
1927                                            if (orderByComparator.isAscending() ^ previous) {
1928                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1929                                            }
1930                                            else {
1931                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1932                                            }
1933                                    }
1934                                    else {
1935                                            if (orderByComparator.isAscending() ^ previous) {
1936                                                    query.append(WHERE_GREATER_THAN);
1937                                            }
1938                                            else {
1939                                                    query.append(WHERE_LESSER_THAN);
1940                                            }
1941                                    }
1942                            }
1943    
1944                            query.append(ORDER_BY_CLAUSE);
1945    
1946                            String[] orderByFields = orderByComparator.getOrderByFields();
1947    
1948                            for (int i = 0; i < orderByFields.length; i++) {
1949                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1950                                    query.append(orderByFields[i]);
1951    
1952                                    if ((i + 1) < orderByFields.length) {
1953                                            if (orderByComparator.isAscending() ^ previous) {
1954                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1955                                            }
1956                                            else {
1957                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1958                                            }
1959                                    }
1960                                    else {
1961                                            if (orderByComparator.isAscending() ^ previous) {
1962                                                    query.append(ORDER_BY_ASC);
1963                                            }
1964                                            else {
1965                                                    query.append(ORDER_BY_DESC);
1966                                            }
1967                                    }
1968                            }
1969                    }
1970    
1971                    else {
1972                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1973                    }
1974    
1975                    String sql = query.toString();
1976    
1977                    Query q = session.createQuery(sql);
1978    
1979                    q.setFirstResult(0);
1980                    q.setMaxResults(2);
1981    
1982                    QueryPos qPos = QueryPos.getInstance(q);
1983    
1984                    if (uuid != null) {
1985                            qPos.add(uuid);
1986                    }
1987    
1988                    if (orderByComparator != null) {
1989                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1990    
1991                            for (Object value : values) {
1992                                    qPos.add(value);
1993                            }
1994                    }
1995    
1996                    List<MBMessage> list = q.list();
1997    
1998                    if (list.size() == 2) {
1999                            return list.get(1);
2000                    }
2001                    else {
2002                            return null;
2003                    }
2004            }
2005    
2006            /**
2007             * 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.
2008             *
2009             * @param uuid the uuid
2010             * @param groupId the group ID
2011             * @return the matching message-boards message
2012             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2013             * @throws SystemException if a system exception occurred
2014             */
2015            public MBMessage findByUUID_G(String uuid, long groupId)
2016                    throws NoSuchMessageException, SystemException {
2017                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
2018    
2019                    if (mbMessage == null) {
2020                            StringBundler msg = new StringBundler(6);
2021    
2022                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2023    
2024                            msg.append("uuid=");
2025                            msg.append(uuid);
2026    
2027                            msg.append(", groupId=");
2028                            msg.append(groupId);
2029    
2030                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2031    
2032                            if (_log.isWarnEnabled()) {
2033                                    _log.warn(msg.toString());
2034                            }
2035    
2036                            throw new NoSuchMessageException(msg.toString());
2037                    }
2038    
2039                    return mbMessage;
2040            }
2041    
2042            /**
2043             * 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.
2044             *
2045             * @param uuid the uuid
2046             * @param groupId the group ID
2047             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2048             * @throws SystemException if a system exception occurred
2049             */
2050            public MBMessage fetchByUUID_G(String uuid, long groupId)
2051                    throws SystemException {
2052                    return fetchByUUID_G(uuid, groupId, true);
2053            }
2054    
2055            /**
2056             * 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.
2057             *
2058             * @param uuid the uuid
2059             * @param groupId the group ID
2060             * @param retrieveFromCache whether to use the finder cache
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                    boolean retrieveFromCache) throws SystemException {
2066                    Object[] finderArgs = new Object[] { uuid, groupId };
2067    
2068                    Object result = null;
2069    
2070                    if (retrieveFromCache) {
2071                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
2072                                            finderArgs, this);
2073                    }
2074    
2075                    if (result == null) {
2076                            StringBundler query = new StringBundler(4);
2077    
2078                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2079    
2080                            if (uuid == null) {
2081                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2082                            }
2083                            else {
2084                                    if (uuid.equals(StringPool.BLANK)) {
2085                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2086                                    }
2087                                    else {
2088                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2089                                    }
2090                            }
2091    
2092                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2093    
2094                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2095    
2096                            String sql = query.toString();
2097    
2098                            Session session = null;
2099    
2100                            try {
2101                                    session = openSession();
2102    
2103                                    Query q = session.createQuery(sql);
2104    
2105                                    QueryPos qPos = QueryPos.getInstance(q);
2106    
2107                                    if (uuid != null) {
2108                                            qPos.add(uuid);
2109                                    }
2110    
2111                                    qPos.add(groupId);
2112    
2113                                    List<MBMessage> list = q.list();
2114    
2115                                    result = list;
2116    
2117                                    MBMessage mbMessage = null;
2118    
2119                                    if (list.isEmpty()) {
2120                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2121                                                    finderArgs, list);
2122                                    }
2123                                    else {
2124                                            mbMessage = list.get(0);
2125    
2126                                            cacheResult(mbMessage);
2127    
2128                                            if ((mbMessage.getUuid() == null) ||
2129                                                            !mbMessage.getUuid().equals(uuid) ||
2130                                                            (mbMessage.getGroupId() != groupId)) {
2131                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2132                                                            finderArgs, mbMessage);
2133                                            }
2134                                    }
2135    
2136                                    return mbMessage;
2137                            }
2138                            catch (Exception e) {
2139                                    throw processException(e);
2140                            }
2141                            finally {
2142                                    if (result == null) {
2143                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
2144                                                    finderArgs);
2145                                    }
2146    
2147                                    closeSession(session);
2148                            }
2149                    }
2150                    else {
2151                            if (result instanceof List<?>) {
2152                                    return null;
2153                            }
2154                            else {
2155                                    return (MBMessage)result;
2156                            }
2157                    }
2158            }
2159    
2160            /**
2161             * Returns all the message-boards messages where groupId = &#63;.
2162             *
2163             * @param groupId the group ID
2164             * @return the matching message-boards messages
2165             * @throws SystemException if a system exception occurred
2166             */
2167            public List<MBMessage> findByGroupId(long groupId)
2168                    throws SystemException {
2169                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2170            }
2171    
2172            /**
2173             * Returns a range of all the message-boards messages where groupId = &#63;.
2174             *
2175             * <p>
2176             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2177             * </p>
2178             *
2179             * @param groupId the group ID
2180             * @param start the lower bound of the range of message-boards messages
2181             * @param end the upper bound of the range of message-boards messages (not inclusive)
2182             * @return the range of matching message-boards messages
2183             * @throws SystemException if a system exception occurred
2184             */
2185            public List<MBMessage> findByGroupId(long groupId, int start, int end)
2186                    throws SystemException {
2187                    return findByGroupId(groupId, start, end, null);
2188            }
2189    
2190            /**
2191             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
2192             *
2193             * <p>
2194             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2195             * </p>
2196             *
2197             * @param groupId the group ID
2198             * @param start the lower bound of the range of message-boards messages
2199             * @param end the upper bound of the range of message-boards messages (not inclusive)
2200             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2201             * @return the ordered range of matching message-boards messages
2202             * @throws SystemException if a system exception occurred
2203             */
2204            public List<MBMessage> findByGroupId(long groupId, int start, int end,
2205                    OrderByComparator orderByComparator) throws SystemException {
2206                    FinderPath finderPath = null;
2207                    Object[] finderArgs = null;
2208    
2209                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2210                                    (orderByComparator == null)) {
2211                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
2212                            finderArgs = new Object[] { groupId };
2213                    }
2214                    else {
2215                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
2216                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
2217                    }
2218    
2219                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2220                                    finderArgs, this);
2221    
2222                    if (list == null) {
2223                            StringBundler query = null;
2224    
2225                            if (orderByComparator != null) {
2226                                    query = new StringBundler(3 +
2227                                                    (orderByComparator.getOrderByFields().length * 3));
2228                            }
2229                            else {
2230                                    query = new StringBundler(3);
2231                            }
2232    
2233                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2234    
2235                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2236    
2237                            if (orderByComparator != null) {
2238                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2239                                            orderByComparator);
2240                            }
2241    
2242                            else {
2243                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2244                            }
2245    
2246                            String sql = query.toString();
2247    
2248                            Session session = null;
2249    
2250                            try {
2251                                    session = openSession();
2252    
2253                                    Query q = session.createQuery(sql);
2254    
2255                                    QueryPos qPos = QueryPos.getInstance(q);
2256    
2257                                    qPos.add(groupId);
2258    
2259                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2260                                                    end);
2261                            }
2262                            catch (Exception e) {
2263                                    throw processException(e);
2264                            }
2265                            finally {
2266                                    if (list == null) {
2267                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2268                                    }
2269                                    else {
2270                                            cacheResult(list);
2271    
2272                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2273                                    }
2274    
2275                                    closeSession(session);
2276                            }
2277                    }
2278    
2279                    return list;
2280            }
2281    
2282            /**
2283             * Returns the first message-boards message in the ordered set where groupId = &#63;.
2284             *
2285             * <p>
2286             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2287             * </p>
2288             *
2289             * @param groupId the group ID
2290             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2291             * @return the first matching message-boards message
2292             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2293             * @throws SystemException if a system exception occurred
2294             */
2295            public MBMessage findByGroupId_First(long groupId,
2296                    OrderByComparator orderByComparator)
2297                    throws NoSuchMessageException, SystemException {
2298                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
2299    
2300                    if (list.isEmpty()) {
2301                            StringBundler msg = new StringBundler(4);
2302    
2303                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2304    
2305                            msg.append("groupId=");
2306                            msg.append(groupId);
2307    
2308                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2309    
2310                            throw new NoSuchMessageException(msg.toString());
2311                    }
2312                    else {
2313                            return list.get(0);
2314                    }
2315            }
2316    
2317            /**
2318             * Returns the last message-boards message in the ordered set where groupId = &#63;.
2319             *
2320             * <p>
2321             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2322             * </p>
2323             *
2324             * @param groupId the group ID
2325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2326             * @return the last matching message-boards message
2327             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2328             * @throws SystemException if a system exception occurred
2329             */
2330            public MBMessage findByGroupId_Last(long groupId,
2331                    OrderByComparator orderByComparator)
2332                    throws NoSuchMessageException, SystemException {
2333                    int count = countByGroupId(groupId);
2334    
2335                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
2336                                    orderByComparator);
2337    
2338                    if (list.isEmpty()) {
2339                            StringBundler msg = new StringBundler(4);
2340    
2341                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2342    
2343                            msg.append("groupId=");
2344                            msg.append(groupId);
2345    
2346                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2347    
2348                            throw new NoSuchMessageException(msg.toString());
2349                    }
2350                    else {
2351                            return list.get(0);
2352                    }
2353            }
2354    
2355            /**
2356             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
2357             *
2358             * <p>
2359             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2360             * </p>
2361             *
2362             * @param messageId the primary key of the current message-boards message
2363             * @param groupId the group ID
2364             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2365             * @return the previous, current, and next message-boards message
2366             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2367             * @throws SystemException if a system exception occurred
2368             */
2369            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
2370                    OrderByComparator orderByComparator)
2371                    throws NoSuchMessageException, SystemException {
2372                    MBMessage mbMessage = findByPrimaryKey(messageId);
2373    
2374                    Session session = null;
2375    
2376                    try {
2377                            session = openSession();
2378    
2379                            MBMessage[] array = new MBMessageImpl[3];
2380    
2381                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
2382                                            orderByComparator, true);
2383    
2384                            array[1] = mbMessage;
2385    
2386                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
2387                                            orderByComparator, false);
2388    
2389                            return array;
2390                    }
2391                    catch (Exception e) {
2392                            throw processException(e);
2393                    }
2394                    finally {
2395                            closeSession(session);
2396                    }
2397            }
2398    
2399            protected MBMessage getByGroupId_PrevAndNext(Session session,
2400                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
2401                    boolean previous) {
2402                    StringBundler query = null;
2403    
2404                    if (orderByComparator != null) {
2405                            query = new StringBundler(6 +
2406                                            (orderByComparator.getOrderByFields().length * 6));
2407                    }
2408                    else {
2409                            query = new StringBundler(3);
2410                    }
2411    
2412                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2413    
2414                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2415    
2416                    if (orderByComparator != null) {
2417                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2418    
2419                            if (orderByConditionFields.length > 0) {
2420                                    query.append(WHERE_AND);
2421                            }
2422    
2423                            for (int i = 0; i < orderByConditionFields.length; i++) {
2424                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2425                                    query.append(orderByConditionFields[i]);
2426    
2427                                    if ((i + 1) < orderByConditionFields.length) {
2428                                            if (orderByComparator.isAscending() ^ previous) {
2429                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2430                                            }
2431                                            else {
2432                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2433                                            }
2434                                    }
2435                                    else {
2436                                            if (orderByComparator.isAscending() ^ previous) {
2437                                                    query.append(WHERE_GREATER_THAN);
2438                                            }
2439                                            else {
2440                                                    query.append(WHERE_LESSER_THAN);
2441                                            }
2442                                    }
2443                            }
2444    
2445                            query.append(ORDER_BY_CLAUSE);
2446    
2447                            String[] orderByFields = orderByComparator.getOrderByFields();
2448    
2449                            for (int i = 0; i < orderByFields.length; i++) {
2450                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2451                                    query.append(orderByFields[i]);
2452    
2453                                    if ((i + 1) < orderByFields.length) {
2454                                            if (orderByComparator.isAscending() ^ previous) {
2455                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2456                                            }
2457                                            else {
2458                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2459                                            }
2460                                    }
2461                                    else {
2462                                            if (orderByComparator.isAscending() ^ previous) {
2463                                                    query.append(ORDER_BY_ASC);
2464                                            }
2465                                            else {
2466                                                    query.append(ORDER_BY_DESC);
2467                                            }
2468                                    }
2469                            }
2470                    }
2471    
2472                    else {
2473                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2474                    }
2475    
2476                    String sql = query.toString();
2477    
2478                    Query q = session.createQuery(sql);
2479    
2480                    q.setFirstResult(0);
2481                    q.setMaxResults(2);
2482    
2483                    QueryPos qPos = QueryPos.getInstance(q);
2484    
2485                    qPos.add(groupId);
2486    
2487                    if (orderByComparator != null) {
2488                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2489    
2490                            for (Object value : values) {
2491                                    qPos.add(value);
2492                            }
2493                    }
2494    
2495                    List<MBMessage> list = q.list();
2496    
2497                    if (list.size() == 2) {
2498                            return list.get(1);
2499                    }
2500                    else {
2501                            return null;
2502                    }
2503            }
2504    
2505            /**
2506             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
2507             *
2508             * @param groupId the group ID
2509             * @return the matching message-boards messages that the user has permission to view
2510             * @throws SystemException if a system exception occurred
2511             */
2512            public List<MBMessage> filterFindByGroupId(long groupId)
2513                    throws SystemException {
2514                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
2515                            QueryUtil.ALL_POS, null);
2516            }
2517    
2518            /**
2519             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
2520             *
2521             * <p>
2522             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2523             * </p>
2524             *
2525             * @param groupId the group ID
2526             * @param start the lower bound of the range of message-boards messages
2527             * @param end the upper bound of the range of message-boards messages (not inclusive)
2528             * @return the range of matching message-boards messages that the user has permission to view
2529             * @throws SystemException if a system exception occurred
2530             */
2531            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end)
2532                    throws SystemException {
2533                    return filterFindByGroupId(groupId, start, end, null);
2534            }
2535    
2536            /**
2537             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
2538             *
2539             * <p>
2540             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2541             * </p>
2542             *
2543             * @param groupId the group ID
2544             * @param start the lower bound of the range of message-boards messages
2545             * @param end the upper bound of the range of message-boards messages (not inclusive)
2546             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2547             * @return the ordered range of matching message-boards messages that the user has permission to view
2548             * @throws SystemException if a system exception occurred
2549             */
2550            public List<MBMessage> filterFindByGroupId(long groupId, int start,
2551                    int end, OrderByComparator orderByComparator) throws SystemException {
2552                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2553                            return findByGroupId(groupId, start, end, orderByComparator);
2554                    }
2555    
2556                    StringBundler query = null;
2557    
2558                    if (orderByComparator != null) {
2559                            query = new StringBundler(3 +
2560                                            (orderByComparator.getOrderByFields().length * 3));
2561                    }
2562                    else {
2563                            query = new StringBundler(3);
2564                    }
2565    
2566                    if (getDB().isSupportsInlineDistinct()) {
2567                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2568                    }
2569                    else {
2570                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2571                    }
2572    
2573                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2574    
2575                    if (!getDB().isSupportsInlineDistinct()) {
2576                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2577                    }
2578    
2579                    if (orderByComparator != null) {
2580                            if (getDB().isSupportsInlineDistinct()) {
2581                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2582                                            orderByComparator);
2583                            }
2584                            else {
2585                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2586                                            orderByComparator);
2587                            }
2588                    }
2589    
2590                    else {
2591                            if (getDB().isSupportsInlineDistinct()) {
2592                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2593                            }
2594                            else {
2595                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2596                            }
2597                    }
2598    
2599                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2600                                    MBMessage.class.getName(),
2601                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2602    
2603                    Session session = null;
2604    
2605                    try {
2606                            session = openSession();
2607    
2608                            SQLQuery q = session.createSQLQuery(sql);
2609    
2610                            if (getDB().isSupportsInlineDistinct()) {
2611                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2612                            }
2613                            else {
2614                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2615                            }
2616    
2617                            QueryPos qPos = QueryPos.getInstance(q);
2618    
2619                            qPos.add(groupId);
2620    
2621                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
2622                    }
2623                    catch (Exception e) {
2624                            throw processException(e);
2625                    }
2626                    finally {
2627                            closeSession(session);
2628                    }
2629            }
2630    
2631            /**
2632             * 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;.
2633             *
2634             * @param messageId the primary key of the current message-boards message
2635             * @param groupId the group ID
2636             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2637             * @return the previous, current, and next message-boards message
2638             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2639             * @throws SystemException if a system exception occurred
2640             */
2641            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
2642                    long groupId, OrderByComparator orderByComparator)
2643                    throws NoSuchMessageException, SystemException {
2644                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2645                            return findByGroupId_PrevAndNext(messageId, groupId,
2646                                    orderByComparator);
2647                    }
2648    
2649                    MBMessage mbMessage = findByPrimaryKey(messageId);
2650    
2651                    Session session = null;
2652    
2653                    try {
2654                            session = openSession();
2655    
2656                            MBMessage[] array = new MBMessageImpl[3];
2657    
2658                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2659                                            groupId, orderByComparator, true);
2660    
2661                            array[1] = mbMessage;
2662    
2663                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
2664                                            groupId, orderByComparator, false);
2665    
2666                            return array;
2667                    }
2668                    catch (Exception e) {
2669                            throw processException(e);
2670                    }
2671                    finally {
2672                            closeSession(session);
2673                    }
2674            }
2675    
2676            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
2677                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
2678                    boolean previous) {
2679                    StringBundler query = null;
2680    
2681                    if (orderByComparator != null) {
2682                            query = new StringBundler(6 +
2683                                            (orderByComparator.getOrderByFields().length * 6));
2684                    }
2685                    else {
2686                            query = new StringBundler(3);
2687                    }
2688    
2689                    if (getDB().isSupportsInlineDistinct()) {
2690                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2691                    }
2692                    else {
2693                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2694                    }
2695    
2696                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2697    
2698                    if (!getDB().isSupportsInlineDistinct()) {
2699                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2700                    }
2701    
2702                    if (orderByComparator != null) {
2703                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2704    
2705                            if (orderByConditionFields.length > 0) {
2706                                    query.append(WHERE_AND);
2707                            }
2708    
2709                            for (int i = 0; i < orderByConditionFields.length; i++) {
2710                                    if (getDB().isSupportsInlineDistinct()) {
2711                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2712                                    }
2713                                    else {
2714                                            query.append(_ORDER_BY_ENTITY_TABLE);
2715                                    }
2716    
2717                                    query.append(orderByConditionFields[i]);
2718    
2719                                    if ((i + 1) < orderByConditionFields.length) {
2720                                            if (orderByComparator.isAscending() ^ previous) {
2721                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2722                                            }
2723                                            else {
2724                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2725                                            }
2726                                    }
2727                                    else {
2728                                            if (orderByComparator.isAscending() ^ previous) {
2729                                                    query.append(WHERE_GREATER_THAN);
2730                                            }
2731                                            else {
2732                                                    query.append(WHERE_LESSER_THAN);
2733                                            }
2734                                    }
2735                            }
2736    
2737                            query.append(ORDER_BY_CLAUSE);
2738    
2739                            String[] orderByFields = orderByComparator.getOrderByFields();
2740    
2741                            for (int i = 0; i < orderByFields.length; i++) {
2742                                    if (getDB().isSupportsInlineDistinct()) {
2743                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2744                                    }
2745                                    else {
2746                                            query.append(_ORDER_BY_ENTITY_TABLE);
2747                                    }
2748    
2749                                    query.append(orderByFields[i]);
2750    
2751                                    if ((i + 1) < orderByFields.length) {
2752                                            if (orderByComparator.isAscending() ^ previous) {
2753                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2754                                            }
2755                                            else {
2756                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2757                                            }
2758                                    }
2759                                    else {
2760                                            if (orderByComparator.isAscending() ^ previous) {
2761                                                    query.append(ORDER_BY_ASC);
2762                                            }
2763                                            else {
2764                                                    query.append(ORDER_BY_DESC);
2765                                            }
2766                                    }
2767                            }
2768                    }
2769    
2770                    else {
2771                            if (getDB().isSupportsInlineDistinct()) {
2772                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2773                            }
2774                            else {
2775                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2776                            }
2777                    }
2778    
2779                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2780                                    MBMessage.class.getName(),
2781                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2782    
2783                    SQLQuery q = session.createSQLQuery(sql);
2784    
2785                    q.setFirstResult(0);
2786                    q.setMaxResults(2);
2787    
2788                    if (getDB().isSupportsInlineDistinct()) {
2789                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2790                    }
2791                    else {
2792                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2793                    }
2794    
2795                    QueryPos qPos = QueryPos.getInstance(q);
2796    
2797                    qPos.add(groupId);
2798    
2799                    if (orderByComparator != null) {
2800                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2801    
2802                            for (Object value : values) {
2803                                    qPos.add(value);
2804                            }
2805                    }
2806    
2807                    List<MBMessage> list = q.list();
2808    
2809                    if (list.size() == 2) {
2810                            return list.get(1);
2811                    }
2812                    else {
2813                            return null;
2814                    }
2815            }
2816    
2817            /**
2818             * Returns all the message-boards messages where companyId = &#63;.
2819             *
2820             * @param companyId the company ID
2821             * @return the matching message-boards messages
2822             * @throws SystemException if a system exception occurred
2823             */
2824            public List<MBMessage> findByCompanyId(long companyId)
2825                    throws SystemException {
2826                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2827                            null);
2828            }
2829    
2830            /**
2831             * Returns a range of all the message-boards messages where companyId = &#63;.
2832             *
2833             * <p>
2834             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2835             * </p>
2836             *
2837             * @param companyId the company ID
2838             * @param start the lower bound of the range of message-boards messages
2839             * @param end the upper bound of the range of message-boards messages (not inclusive)
2840             * @return the range of matching message-boards messages
2841             * @throws SystemException if a system exception occurred
2842             */
2843            public List<MBMessage> findByCompanyId(long companyId, int start, int end)
2844                    throws SystemException {
2845                    return findByCompanyId(companyId, start, end, null);
2846            }
2847    
2848            /**
2849             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2850             *
2851             * <p>
2852             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2853             * </p>
2854             *
2855             * @param companyId the company ID
2856             * @param start the lower bound of the range of message-boards messages
2857             * @param end the upper bound of the range of message-boards messages (not inclusive)
2858             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2859             * @return the ordered range of matching message-boards messages
2860             * @throws SystemException if a system exception occurred
2861             */
2862            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2863                    OrderByComparator orderByComparator) throws SystemException {
2864                    FinderPath finderPath = null;
2865                    Object[] finderArgs = null;
2866    
2867                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2868                                    (orderByComparator == null)) {
2869                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2870                            finderArgs = new Object[] { companyId };
2871                    }
2872                    else {
2873                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2874                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2875                    }
2876    
2877                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2878                                    finderArgs, this);
2879    
2880                    if (list == null) {
2881                            StringBundler query = null;
2882    
2883                            if (orderByComparator != null) {
2884                                    query = new StringBundler(3 +
2885                                                    (orderByComparator.getOrderByFields().length * 3));
2886                            }
2887                            else {
2888                                    query = new StringBundler(3);
2889                            }
2890    
2891                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2892    
2893                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2894    
2895                            if (orderByComparator != null) {
2896                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2897                                            orderByComparator);
2898                            }
2899    
2900                            else {
2901                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2902                            }
2903    
2904                            String sql = query.toString();
2905    
2906                            Session session = null;
2907    
2908                            try {
2909                                    session = openSession();
2910    
2911                                    Query q = session.createQuery(sql);
2912    
2913                                    QueryPos qPos = QueryPos.getInstance(q);
2914    
2915                                    qPos.add(companyId);
2916    
2917                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2918                                                    end);
2919                            }
2920                            catch (Exception e) {
2921                                    throw processException(e);
2922                            }
2923                            finally {
2924                                    if (list == null) {
2925                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2926                                    }
2927                                    else {
2928                                            cacheResult(list);
2929    
2930                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2931                                    }
2932    
2933                                    closeSession(session);
2934                            }
2935                    }
2936    
2937                    return list;
2938            }
2939    
2940            /**
2941             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2942             *
2943             * <p>
2944             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2945             * </p>
2946             *
2947             * @param companyId the company ID
2948             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2949             * @return the first matching message-boards message
2950             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2951             * @throws SystemException if a system exception occurred
2952             */
2953            public MBMessage findByCompanyId_First(long companyId,
2954                    OrderByComparator orderByComparator)
2955                    throws NoSuchMessageException, SystemException {
2956                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
2957                                    orderByComparator);
2958    
2959                    if (list.isEmpty()) {
2960                            StringBundler msg = new StringBundler(4);
2961    
2962                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2963    
2964                            msg.append("companyId=");
2965                            msg.append(companyId);
2966    
2967                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2968    
2969                            throw new NoSuchMessageException(msg.toString());
2970                    }
2971                    else {
2972                            return list.get(0);
2973                    }
2974            }
2975    
2976            /**
2977             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2978             *
2979             * <p>
2980             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2981             * </p>
2982             *
2983             * @param companyId the company ID
2984             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2985             * @return the last matching message-boards message
2986             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2987             * @throws SystemException if a system exception occurred
2988             */
2989            public MBMessage findByCompanyId_Last(long companyId,
2990                    OrderByComparator orderByComparator)
2991                    throws NoSuchMessageException, SystemException {
2992                    int count = countByCompanyId(companyId);
2993    
2994                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
2995                                    orderByComparator);
2996    
2997                    if (list.isEmpty()) {
2998                            StringBundler msg = new StringBundler(4);
2999    
3000                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3001    
3002                            msg.append("companyId=");
3003                            msg.append(companyId);
3004    
3005                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3006    
3007                            throw new NoSuchMessageException(msg.toString());
3008                    }
3009                    else {
3010                            return list.get(0);
3011                    }
3012            }
3013    
3014            /**
3015             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
3016             *
3017             * <p>
3018             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3019             * </p>
3020             *
3021             * @param messageId the primary key of the current message-boards message
3022             * @param companyId the company ID
3023             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3024             * @return the previous, current, and next message-boards message
3025             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3026             * @throws SystemException if a system exception occurred
3027             */
3028            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
3029                    long companyId, OrderByComparator orderByComparator)
3030                    throws NoSuchMessageException, SystemException {
3031                    MBMessage mbMessage = findByPrimaryKey(messageId);
3032    
3033                    Session session = null;
3034    
3035                    try {
3036                            session = openSession();
3037    
3038                            MBMessage[] array = new MBMessageImpl[3];
3039    
3040                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
3041                                            companyId, orderByComparator, true);
3042    
3043                            array[1] = mbMessage;
3044    
3045                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
3046                                            companyId, orderByComparator, false);
3047    
3048                            return array;
3049                    }
3050                    catch (Exception e) {
3051                            throw processException(e);
3052                    }
3053                    finally {
3054                            closeSession(session);
3055                    }
3056            }
3057    
3058            protected MBMessage getByCompanyId_PrevAndNext(Session session,
3059                    MBMessage mbMessage, long companyId,
3060                    OrderByComparator orderByComparator, boolean previous) {
3061                    StringBundler query = null;
3062    
3063                    if (orderByComparator != null) {
3064                            query = new StringBundler(6 +
3065                                            (orderByComparator.getOrderByFields().length * 6));
3066                    }
3067                    else {
3068                            query = new StringBundler(3);
3069                    }
3070    
3071                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3072    
3073                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3074    
3075                    if (orderByComparator != null) {
3076                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3077    
3078                            if (orderByConditionFields.length > 0) {
3079                                    query.append(WHERE_AND);
3080                            }
3081    
3082                            for (int i = 0; i < orderByConditionFields.length; i++) {
3083                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3084                                    query.append(orderByConditionFields[i]);
3085    
3086                                    if ((i + 1) < orderByConditionFields.length) {
3087                                            if (orderByComparator.isAscending() ^ previous) {
3088                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3089                                            }
3090                                            else {
3091                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3092                                            }
3093                                    }
3094                                    else {
3095                                            if (orderByComparator.isAscending() ^ previous) {
3096                                                    query.append(WHERE_GREATER_THAN);
3097                                            }
3098                                            else {
3099                                                    query.append(WHERE_LESSER_THAN);
3100                                            }
3101                                    }
3102                            }
3103    
3104                            query.append(ORDER_BY_CLAUSE);
3105    
3106                            String[] orderByFields = orderByComparator.getOrderByFields();
3107    
3108                            for (int i = 0; i < orderByFields.length; i++) {
3109                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3110                                    query.append(orderByFields[i]);
3111    
3112                                    if ((i + 1) < orderByFields.length) {
3113                                            if (orderByComparator.isAscending() ^ previous) {
3114                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3115                                            }
3116                                            else {
3117                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3118                                            }
3119                                    }
3120                                    else {
3121                                            if (orderByComparator.isAscending() ^ previous) {
3122                                                    query.append(ORDER_BY_ASC);
3123                                            }
3124                                            else {
3125                                                    query.append(ORDER_BY_DESC);
3126                                            }
3127                                    }
3128                            }
3129                    }
3130    
3131                    else {
3132                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3133                    }
3134    
3135                    String sql = query.toString();
3136    
3137                    Query q = session.createQuery(sql);
3138    
3139                    q.setFirstResult(0);
3140                    q.setMaxResults(2);
3141    
3142                    QueryPos qPos = QueryPos.getInstance(q);
3143    
3144                    qPos.add(companyId);
3145    
3146                    if (orderByComparator != null) {
3147                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3148    
3149                            for (Object value : values) {
3150                                    qPos.add(value);
3151                            }
3152                    }
3153    
3154                    List<MBMessage> list = q.list();
3155    
3156                    if (list.size() == 2) {
3157                            return list.get(1);
3158                    }
3159                    else {
3160                            return null;
3161                    }
3162            }
3163    
3164            /**
3165             * Returns all the message-boards messages where threadId = &#63;.
3166             *
3167             * @param threadId the thread ID
3168             * @return the matching message-boards messages
3169             * @throws SystemException if a system exception occurred
3170             */
3171            public List<MBMessage> findByThreadId(long threadId)
3172                    throws SystemException {
3173                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3174                            null);
3175            }
3176    
3177            /**
3178             * Returns a range of all the message-boards messages where threadId = &#63;.
3179             *
3180             * <p>
3181             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3182             * </p>
3183             *
3184             * @param threadId the thread ID
3185             * @param start the lower bound of the range of message-boards messages
3186             * @param end the upper bound of the range of message-boards messages (not inclusive)
3187             * @return the range of matching message-boards messages
3188             * @throws SystemException if a system exception occurred
3189             */
3190            public List<MBMessage> findByThreadId(long threadId, int start, int end)
3191                    throws SystemException {
3192                    return findByThreadId(threadId, start, end, null);
3193            }
3194    
3195            /**
3196             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3197             *
3198             * <p>
3199             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3200             * </p>
3201             *
3202             * @param threadId the thread ID
3203             * @param start the lower bound of the range of message-boards messages
3204             * @param end the upper bound of the range of message-boards messages (not inclusive)
3205             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3206             * @return the ordered range of matching message-boards messages
3207             * @throws SystemException if a system exception occurred
3208             */
3209            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3210                    OrderByComparator orderByComparator) throws SystemException {
3211                    FinderPath finderPath = null;
3212                    Object[] finderArgs = null;
3213    
3214                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3215                                    (orderByComparator == null)) {
3216                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
3217                            finderArgs = new Object[] { threadId };
3218                    }
3219                    else {
3220                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
3221                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3222                    }
3223    
3224                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3225                                    finderArgs, this);
3226    
3227                    if (list == null) {
3228                            StringBundler query = null;
3229    
3230                            if (orderByComparator != null) {
3231                                    query = new StringBundler(3 +
3232                                                    (orderByComparator.getOrderByFields().length * 3));
3233                            }
3234                            else {
3235                                    query = new StringBundler(3);
3236                            }
3237    
3238                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3239    
3240                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3241    
3242                            if (orderByComparator != null) {
3243                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3244                                            orderByComparator);
3245                            }
3246    
3247                            else {
3248                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3249                            }
3250    
3251                            String sql = query.toString();
3252    
3253                            Session session = null;
3254    
3255                            try {
3256                                    session = openSession();
3257    
3258                                    Query q = session.createQuery(sql);
3259    
3260                                    QueryPos qPos = QueryPos.getInstance(q);
3261    
3262                                    qPos.add(threadId);
3263    
3264                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3265                                                    end);
3266                            }
3267                            catch (Exception e) {
3268                                    throw processException(e);
3269                            }
3270                            finally {
3271                                    if (list == null) {
3272                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3273                                    }
3274                                    else {
3275                                            cacheResult(list);
3276    
3277                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3278                                    }
3279    
3280                                    closeSession(session);
3281                            }
3282                    }
3283    
3284                    return list;
3285            }
3286    
3287            /**
3288             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3289             *
3290             * <p>
3291             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3292             * </p>
3293             *
3294             * @param threadId the thread ID
3295             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3296             * @return the first matching message-boards message
3297             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3298             * @throws SystemException if a system exception occurred
3299             */
3300            public MBMessage findByThreadId_First(long threadId,
3301                    OrderByComparator orderByComparator)
3302                    throws NoSuchMessageException, SystemException {
3303                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
3304    
3305                    if (list.isEmpty()) {
3306                            StringBundler msg = new StringBundler(4);
3307    
3308                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3309    
3310                            msg.append("threadId=");
3311                            msg.append(threadId);
3312    
3313                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3314    
3315                            throw new NoSuchMessageException(msg.toString());
3316                    }
3317                    else {
3318                            return list.get(0);
3319                    }
3320            }
3321    
3322            /**
3323             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3324             *
3325             * <p>
3326             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3327             * </p>
3328             *
3329             * @param threadId the thread ID
3330             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3331             * @return the last matching message-boards message
3332             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3333             * @throws SystemException if a system exception occurred
3334             */
3335            public MBMessage findByThreadId_Last(long threadId,
3336                    OrderByComparator orderByComparator)
3337                    throws NoSuchMessageException, SystemException {
3338                    int count = countByThreadId(threadId);
3339    
3340                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
3341                                    orderByComparator);
3342    
3343                    if (list.isEmpty()) {
3344                            StringBundler msg = new StringBundler(4);
3345    
3346                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3347    
3348                            msg.append("threadId=");
3349                            msg.append(threadId);
3350    
3351                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3352    
3353                            throw new NoSuchMessageException(msg.toString());
3354                    }
3355                    else {
3356                            return list.get(0);
3357                    }
3358            }
3359    
3360            /**
3361             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3362             *
3363             * <p>
3364             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3365             * </p>
3366             *
3367             * @param messageId the primary key of the current message-boards message
3368             * @param threadId the thread ID
3369             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3370             * @return the previous, current, and next message-boards message
3371             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3372             * @throws SystemException if a system exception occurred
3373             */
3374            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
3375                    long threadId, OrderByComparator orderByComparator)
3376                    throws NoSuchMessageException, SystemException {
3377                    MBMessage mbMessage = findByPrimaryKey(messageId);
3378    
3379                    Session session = null;
3380    
3381                    try {
3382                            session = openSession();
3383    
3384                            MBMessage[] array = new MBMessageImpl[3];
3385    
3386                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3387                                            orderByComparator, true);
3388    
3389                            array[1] = mbMessage;
3390    
3391                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3392                                            orderByComparator, false);
3393    
3394                            return array;
3395                    }
3396                    catch (Exception e) {
3397                            throw processException(e);
3398                    }
3399                    finally {
3400                            closeSession(session);
3401                    }
3402            }
3403    
3404            protected MBMessage getByThreadId_PrevAndNext(Session session,
3405                    MBMessage mbMessage, long threadId,
3406                    OrderByComparator orderByComparator, boolean previous) {
3407                    StringBundler query = null;
3408    
3409                    if (orderByComparator != null) {
3410                            query = new StringBundler(6 +
3411                                            (orderByComparator.getOrderByFields().length * 6));
3412                    }
3413                    else {
3414                            query = new StringBundler(3);
3415                    }
3416    
3417                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3418    
3419                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3420    
3421                    if (orderByComparator != null) {
3422                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3423    
3424                            if (orderByConditionFields.length > 0) {
3425                                    query.append(WHERE_AND);
3426                            }
3427    
3428                            for (int i = 0; i < orderByConditionFields.length; i++) {
3429                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3430                                    query.append(orderByConditionFields[i]);
3431    
3432                                    if ((i + 1) < orderByConditionFields.length) {
3433                                            if (orderByComparator.isAscending() ^ previous) {
3434                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3435                                            }
3436                                            else {
3437                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3438                                            }
3439                                    }
3440                                    else {
3441                                            if (orderByComparator.isAscending() ^ previous) {
3442                                                    query.append(WHERE_GREATER_THAN);
3443                                            }
3444                                            else {
3445                                                    query.append(WHERE_LESSER_THAN);
3446                                            }
3447                                    }
3448                            }
3449    
3450                            query.append(ORDER_BY_CLAUSE);
3451    
3452                            String[] orderByFields = orderByComparator.getOrderByFields();
3453    
3454                            for (int i = 0; i < orderByFields.length; i++) {
3455                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3456                                    query.append(orderByFields[i]);
3457    
3458                                    if ((i + 1) < orderByFields.length) {
3459                                            if (orderByComparator.isAscending() ^ previous) {
3460                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3461                                            }
3462                                            else {
3463                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3464                                            }
3465                                    }
3466                                    else {
3467                                            if (orderByComparator.isAscending() ^ previous) {
3468                                                    query.append(ORDER_BY_ASC);
3469                                            }
3470                                            else {
3471                                                    query.append(ORDER_BY_DESC);
3472                                            }
3473                                    }
3474                            }
3475                    }
3476    
3477                    else {
3478                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3479                    }
3480    
3481                    String sql = query.toString();
3482    
3483                    Query q = session.createQuery(sql);
3484    
3485                    q.setFirstResult(0);
3486                    q.setMaxResults(2);
3487    
3488                    QueryPos qPos = QueryPos.getInstance(q);
3489    
3490                    qPos.add(threadId);
3491    
3492                    if (orderByComparator != null) {
3493                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3494    
3495                            for (Object value : values) {
3496                                    qPos.add(value);
3497                            }
3498                    }
3499    
3500                    List<MBMessage> list = q.list();
3501    
3502                    if (list.size() == 2) {
3503                            return list.get(1);
3504                    }
3505                    else {
3506                            return null;
3507                    }
3508            }
3509    
3510            /**
3511             * Returns all the message-boards messages where threadId = &#63;.
3512             *
3513             * @param threadId the thread ID
3514             * @return the matching message-boards messages
3515             * @throws SystemException if a system exception occurred
3516             */
3517            public List<MBMessage> findByThreadReplies(long threadId)
3518                    throws SystemException {
3519                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3520                            QueryUtil.ALL_POS, null);
3521            }
3522    
3523            /**
3524             * Returns a range of all the message-boards messages where threadId = &#63;.
3525             *
3526             * <p>
3527             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3528             * </p>
3529             *
3530             * @param threadId the thread ID
3531             * @param start the lower bound of the range of message-boards messages
3532             * @param end the upper bound of the range of message-boards messages (not inclusive)
3533             * @return the range of matching message-boards messages
3534             * @throws SystemException if a system exception occurred
3535             */
3536            public List<MBMessage> findByThreadReplies(long threadId, int start, int end)
3537                    throws SystemException {
3538                    return findByThreadReplies(threadId, start, end, null);
3539            }
3540    
3541            /**
3542             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3543             *
3544             * <p>
3545             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3546             * </p>
3547             *
3548             * @param threadId the thread ID
3549             * @param start the lower bound of the range of message-boards messages
3550             * @param end the upper bound of the range of message-boards messages (not inclusive)
3551             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3552             * @return the ordered range of matching message-boards messages
3553             * @throws SystemException if a system exception occurred
3554             */
3555            public List<MBMessage> findByThreadReplies(long threadId, int start,
3556                    int end, OrderByComparator orderByComparator) throws SystemException {
3557                    FinderPath finderPath = null;
3558                    Object[] finderArgs = null;
3559    
3560                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3561                                    (orderByComparator == null)) {
3562                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3563                            finderArgs = new Object[] { threadId };
3564                    }
3565                    else {
3566                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3567                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3568                    }
3569    
3570                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3571                                    finderArgs, this);
3572    
3573                    if (list == null) {
3574                            StringBundler query = null;
3575    
3576                            if (orderByComparator != null) {
3577                                    query = new StringBundler(3 +
3578                                                    (orderByComparator.getOrderByFields().length * 3));
3579                            }
3580                            else {
3581                                    query = new StringBundler(3);
3582                            }
3583    
3584                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3585    
3586                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3587    
3588                            if (orderByComparator != null) {
3589                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3590                                            orderByComparator);
3591                            }
3592    
3593                            else {
3594                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3595                            }
3596    
3597                            String sql = query.toString();
3598    
3599                            Session session = null;
3600    
3601                            try {
3602                                    session = openSession();
3603    
3604                                    Query q = session.createQuery(sql);
3605    
3606                                    QueryPos qPos = QueryPos.getInstance(q);
3607    
3608                                    qPos.add(threadId);
3609    
3610                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3611                                                    end);
3612                            }
3613                            catch (Exception e) {
3614                                    throw processException(e);
3615                            }
3616                            finally {
3617                                    if (list == null) {
3618                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3619                                    }
3620                                    else {
3621                                            cacheResult(list);
3622    
3623                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3624                                    }
3625    
3626                                    closeSession(session);
3627                            }
3628                    }
3629    
3630                    return list;
3631            }
3632    
3633            /**
3634             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3635             *
3636             * <p>
3637             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3638             * </p>
3639             *
3640             * @param threadId the thread ID
3641             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3642             * @return the first matching message-boards message
3643             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3644             * @throws SystemException if a system exception occurred
3645             */
3646            public MBMessage findByThreadReplies_First(long threadId,
3647                    OrderByComparator orderByComparator)
3648                    throws NoSuchMessageException, SystemException {
3649                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
3650                                    orderByComparator);
3651    
3652                    if (list.isEmpty()) {
3653                            StringBundler msg = new StringBundler(4);
3654    
3655                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3656    
3657                            msg.append("threadId=");
3658                            msg.append(threadId);
3659    
3660                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3661    
3662                            throw new NoSuchMessageException(msg.toString());
3663                    }
3664                    else {
3665                            return list.get(0);
3666                    }
3667            }
3668    
3669            /**
3670             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3671             *
3672             * <p>
3673             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3674             * </p>
3675             *
3676             * @param threadId the thread ID
3677             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3678             * @return the last matching message-boards message
3679             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3680             * @throws SystemException if a system exception occurred
3681             */
3682            public MBMessage findByThreadReplies_Last(long threadId,
3683                    OrderByComparator orderByComparator)
3684                    throws NoSuchMessageException, SystemException {
3685                    int count = countByThreadReplies(threadId);
3686    
3687                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
3688                                    orderByComparator);
3689    
3690                    if (list.isEmpty()) {
3691                            StringBundler msg = new StringBundler(4);
3692    
3693                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3694    
3695                            msg.append("threadId=");
3696                            msg.append(threadId);
3697    
3698                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3699    
3700                            throw new NoSuchMessageException(msg.toString());
3701                    }
3702                    else {
3703                            return list.get(0);
3704                    }
3705            }
3706    
3707            /**
3708             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3709             *
3710             * <p>
3711             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3712             * </p>
3713             *
3714             * @param messageId the primary key of the current message-boards message
3715             * @param threadId the thread ID
3716             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3717             * @return the previous, current, and next message-boards message
3718             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3719             * @throws SystemException if a system exception occurred
3720             */
3721            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
3722                    long threadId, OrderByComparator orderByComparator)
3723                    throws NoSuchMessageException, SystemException {
3724                    MBMessage mbMessage = findByPrimaryKey(messageId);
3725    
3726                    Session session = null;
3727    
3728                    try {
3729                            session = openSession();
3730    
3731                            MBMessage[] array = new MBMessageImpl[3];
3732    
3733                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
3734                                            threadId, orderByComparator, true);
3735    
3736                            array[1] = mbMessage;
3737    
3738                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
3739                                            threadId, orderByComparator, false);
3740    
3741                            return array;
3742                    }
3743                    catch (Exception e) {
3744                            throw processException(e);
3745                    }
3746                    finally {
3747                            closeSession(session);
3748                    }
3749            }
3750    
3751            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
3752                    MBMessage mbMessage, long threadId,
3753                    OrderByComparator orderByComparator, boolean previous) {
3754                    StringBundler query = null;
3755    
3756                    if (orderByComparator != null) {
3757                            query = new StringBundler(6 +
3758                                            (orderByComparator.getOrderByFields().length * 6));
3759                    }
3760                    else {
3761                            query = new StringBundler(3);
3762                    }
3763    
3764                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3765    
3766                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3767    
3768                    if (orderByComparator != null) {
3769                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3770    
3771                            if (orderByConditionFields.length > 0) {
3772                                    query.append(WHERE_AND);
3773                            }
3774    
3775                            for (int i = 0; i < orderByConditionFields.length; i++) {
3776                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3777                                    query.append(orderByConditionFields[i]);
3778    
3779                                    if ((i + 1) < orderByConditionFields.length) {
3780                                            if (orderByComparator.isAscending() ^ previous) {
3781                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3782                                            }
3783                                            else {
3784                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3785                                            }
3786                                    }
3787                                    else {
3788                                            if (orderByComparator.isAscending() ^ previous) {
3789                                                    query.append(WHERE_GREATER_THAN);
3790                                            }
3791                                            else {
3792                                                    query.append(WHERE_LESSER_THAN);
3793                                            }
3794                                    }
3795                            }
3796    
3797                            query.append(ORDER_BY_CLAUSE);
3798    
3799                            String[] orderByFields = orderByComparator.getOrderByFields();
3800    
3801                            for (int i = 0; i < orderByFields.length; i++) {
3802                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3803                                    query.append(orderByFields[i]);
3804    
3805                                    if ((i + 1) < orderByFields.length) {
3806                                            if (orderByComparator.isAscending() ^ previous) {
3807                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3808                                            }
3809                                            else {
3810                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3811                                            }
3812                                    }
3813                                    else {
3814                                            if (orderByComparator.isAscending() ^ previous) {
3815                                                    query.append(ORDER_BY_ASC);
3816                                            }
3817                                            else {
3818                                                    query.append(ORDER_BY_DESC);
3819                                            }
3820                                    }
3821                            }
3822                    }
3823    
3824                    else {
3825                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3826                    }
3827    
3828                    String sql = query.toString();
3829    
3830                    Query q = session.createQuery(sql);
3831    
3832                    q.setFirstResult(0);
3833                    q.setMaxResults(2);
3834    
3835                    QueryPos qPos = QueryPos.getInstance(q);
3836    
3837                    qPos.add(threadId);
3838    
3839                    if (orderByComparator != null) {
3840                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3841    
3842                            for (Object value : values) {
3843                                    qPos.add(value);
3844                            }
3845                    }
3846    
3847                    List<MBMessage> list = q.list();
3848    
3849                    if (list.size() == 2) {
3850                            return list.get(1);
3851                    }
3852                    else {
3853                            return null;
3854                    }
3855            }
3856    
3857            /**
3858             * Returns all the message-boards messages where userId = &#63;.
3859             *
3860             * @param userId the user ID
3861             * @return the matching message-boards messages
3862             * @throws SystemException if a system exception occurred
3863             */
3864            public List<MBMessage> findByUserId(long userId) throws SystemException {
3865                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3866            }
3867    
3868            /**
3869             * Returns a range of all the message-boards messages where userId = &#63;.
3870             *
3871             * <p>
3872             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3873             * </p>
3874             *
3875             * @param userId the user ID
3876             * @param start the lower bound of the range of message-boards messages
3877             * @param end the upper bound of the range of message-boards messages (not inclusive)
3878             * @return the range of matching message-boards messages
3879             * @throws SystemException if a system exception occurred
3880             */
3881            public List<MBMessage> findByUserId(long userId, int start, int end)
3882                    throws SystemException {
3883                    return findByUserId(userId, start, end, null);
3884            }
3885    
3886            /**
3887             * Returns an ordered range of all the message-boards messages where userId = &#63;.
3888             *
3889             * <p>
3890             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3891             * </p>
3892             *
3893             * @param userId the user ID
3894             * @param start the lower bound of the range of message-boards messages
3895             * @param end the upper bound of the range of message-boards messages (not inclusive)
3896             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3897             * @return the ordered range of matching message-boards messages
3898             * @throws SystemException if a system exception occurred
3899             */
3900            public List<MBMessage> findByUserId(long userId, int start, int end,
3901                    OrderByComparator orderByComparator) throws SystemException {
3902                    FinderPath finderPath = null;
3903                    Object[] finderArgs = null;
3904    
3905                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3906                                    (orderByComparator == null)) {
3907                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
3908                            finderArgs = new Object[] { userId };
3909                    }
3910                    else {
3911                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
3912                            finderArgs = new Object[] { userId, start, end, orderByComparator };
3913                    }
3914    
3915                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3916                                    finderArgs, this);
3917    
3918                    if (list == null) {
3919                            StringBundler query = null;
3920    
3921                            if (orderByComparator != null) {
3922                                    query = new StringBundler(3 +
3923                                                    (orderByComparator.getOrderByFields().length * 3));
3924                            }
3925                            else {
3926                                    query = new StringBundler(3);
3927                            }
3928    
3929                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3930    
3931                            query.append(_FINDER_COLUMN_USERID_USERID_2);
3932    
3933                            if (orderByComparator != null) {
3934                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3935                                            orderByComparator);
3936                            }
3937    
3938                            else {
3939                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3940                            }
3941    
3942                            String sql = query.toString();
3943    
3944                            Session session = null;
3945    
3946                            try {
3947                                    session = openSession();
3948    
3949                                    Query q = session.createQuery(sql);
3950    
3951                                    QueryPos qPos = QueryPos.getInstance(q);
3952    
3953                                    qPos.add(userId);
3954    
3955                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3956                                                    end);
3957                            }
3958                            catch (Exception e) {
3959                                    throw processException(e);
3960                            }
3961                            finally {
3962                                    if (list == null) {
3963                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3964                                    }
3965                                    else {
3966                                            cacheResult(list);
3967    
3968                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3969                                    }
3970    
3971                                    closeSession(session);
3972                            }
3973                    }
3974    
3975                    return list;
3976            }
3977    
3978            /**
3979             * Returns the first message-boards message in the ordered set where userId = &#63;.
3980             *
3981             * <p>
3982             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3983             * </p>
3984             *
3985             * @param userId the user ID
3986             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3987             * @return the first matching message-boards message
3988             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3989             * @throws SystemException if a system exception occurred
3990             */
3991            public MBMessage findByUserId_First(long userId,
3992                    OrderByComparator orderByComparator)
3993                    throws NoSuchMessageException, SystemException {
3994                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
3995    
3996                    if (list.isEmpty()) {
3997                            StringBundler msg = new StringBundler(4);
3998    
3999                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4000    
4001                            msg.append("userId=");
4002                            msg.append(userId);
4003    
4004                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4005    
4006                            throw new NoSuchMessageException(msg.toString());
4007                    }
4008                    else {
4009                            return list.get(0);
4010                    }
4011            }
4012    
4013            /**
4014             * Returns the last message-boards message in the ordered set where userId = &#63;.
4015             *
4016             * <p>
4017             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4018             * </p>
4019             *
4020             * @param userId the user ID
4021             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4022             * @return the last matching message-boards message
4023             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4024             * @throws SystemException if a system exception occurred
4025             */
4026            public MBMessage findByUserId_Last(long userId,
4027                    OrderByComparator orderByComparator)
4028                    throws NoSuchMessageException, SystemException {
4029                    int count = countByUserId(userId);
4030    
4031                    List<MBMessage> list = findByUserId(userId, count - 1, count,
4032                                    orderByComparator);
4033    
4034                    if (list.isEmpty()) {
4035                            StringBundler msg = new StringBundler(4);
4036    
4037                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4038    
4039                            msg.append("userId=");
4040                            msg.append(userId);
4041    
4042                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4043    
4044                            throw new NoSuchMessageException(msg.toString());
4045                    }
4046                    else {
4047                            return list.get(0);
4048                    }
4049            }
4050    
4051            /**
4052             * Returns the message-boards messages before and after the current 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 messageId the primary key of the current message-boards message
4059             * @param userId the user ID
4060             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4061             * @return the previous, current, and next message-boards message
4062             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4063             * @throws SystemException if a system exception occurred
4064             */
4065            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
4066                    OrderByComparator orderByComparator)
4067                    throws NoSuchMessageException, SystemException {
4068                    MBMessage mbMessage = findByPrimaryKey(messageId);
4069    
4070                    Session session = null;
4071    
4072                    try {
4073                            session = openSession();
4074    
4075                            MBMessage[] array = new MBMessageImpl[3];
4076    
4077                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
4078                                            orderByComparator, true);
4079    
4080                            array[1] = mbMessage;
4081    
4082                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
4083                                            orderByComparator, false);
4084    
4085                            return array;
4086                    }
4087                    catch (Exception e) {
4088                            throw processException(e);
4089                    }
4090                    finally {
4091                            closeSession(session);
4092                    }
4093            }
4094    
4095            protected MBMessage getByUserId_PrevAndNext(Session session,
4096                    MBMessage mbMessage, long userId, OrderByComparator orderByComparator,
4097                    boolean previous) {
4098                    StringBundler query = null;
4099    
4100                    if (orderByComparator != null) {
4101                            query = new StringBundler(6 +
4102                                            (orderByComparator.getOrderByFields().length * 6));
4103                    }
4104                    else {
4105                            query = new StringBundler(3);
4106                    }
4107    
4108                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4109    
4110                    query.append(_FINDER_COLUMN_USERID_USERID_2);
4111    
4112                    if (orderByComparator != null) {
4113                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4114    
4115                            if (orderByConditionFields.length > 0) {
4116                                    query.append(WHERE_AND);
4117                            }
4118    
4119                            for (int i = 0; i < orderByConditionFields.length; i++) {
4120                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4121                                    query.append(orderByConditionFields[i]);
4122    
4123                                    if ((i + 1) < orderByConditionFields.length) {
4124                                            if (orderByComparator.isAscending() ^ previous) {
4125                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4126                                            }
4127                                            else {
4128                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4129                                            }
4130                                    }
4131                                    else {
4132                                            if (orderByComparator.isAscending() ^ previous) {
4133                                                    query.append(WHERE_GREATER_THAN);
4134                                            }
4135                                            else {
4136                                                    query.append(WHERE_LESSER_THAN);
4137                                            }
4138                                    }
4139                            }
4140    
4141                            query.append(ORDER_BY_CLAUSE);
4142    
4143                            String[] orderByFields = orderByComparator.getOrderByFields();
4144    
4145                            for (int i = 0; i < orderByFields.length; i++) {
4146                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4147                                    query.append(orderByFields[i]);
4148    
4149                                    if ((i + 1) < orderByFields.length) {
4150                                            if (orderByComparator.isAscending() ^ previous) {
4151                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4152                                            }
4153                                            else {
4154                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4155                                            }
4156                                    }
4157                                    else {
4158                                            if (orderByComparator.isAscending() ^ previous) {
4159                                                    query.append(ORDER_BY_ASC);
4160                                            }
4161                                            else {
4162                                                    query.append(ORDER_BY_DESC);
4163                                            }
4164                                    }
4165                            }
4166                    }
4167    
4168                    else {
4169                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4170                    }
4171    
4172                    String sql = query.toString();
4173    
4174                    Query q = session.createQuery(sql);
4175    
4176                    q.setFirstResult(0);
4177                    q.setMaxResults(2);
4178    
4179                    QueryPos qPos = QueryPos.getInstance(q);
4180    
4181                    qPos.add(userId);
4182    
4183                    if (orderByComparator != null) {
4184                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4185    
4186                            for (Object value : values) {
4187                                    qPos.add(value);
4188                            }
4189                    }
4190    
4191                    List<MBMessage> list = q.list();
4192    
4193                    if (list.size() == 2) {
4194                            return list.get(1);
4195                    }
4196                    else {
4197                            return null;
4198                    }
4199            }
4200    
4201            /**
4202             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4203             *
4204             * @param groupId the group ID
4205             * @param userId the user ID
4206             * @return the matching message-boards messages
4207             * @throws SystemException if a system exception occurred
4208             */
4209            public List<MBMessage> findByG_U(long groupId, long userId)
4210                    throws SystemException {
4211                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4212                            null);
4213            }
4214    
4215            /**
4216             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4217             *
4218             * <p>
4219             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4220             * </p>
4221             *
4222             * @param groupId the group ID
4223             * @param userId the user ID
4224             * @param start the lower bound of the range of message-boards messages
4225             * @param end the upper bound of the range of message-boards messages (not inclusive)
4226             * @return the range of matching message-boards messages
4227             * @throws SystemException if a system exception occurred
4228             */
4229            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4230                    int end) throws SystemException {
4231                    return findByG_U(groupId, userId, start, end, null);
4232            }
4233    
4234            /**
4235             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4236             *
4237             * <p>
4238             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4239             * </p>
4240             *
4241             * @param groupId the group ID
4242             * @param userId the user ID
4243             * @param start the lower bound of the range of message-boards messages
4244             * @param end the upper bound of the range of message-boards messages (not inclusive)
4245             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4246             * @return the ordered range of matching message-boards messages
4247             * @throws SystemException if a system exception occurred
4248             */
4249            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4250                    int end, OrderByComparator orderByComparator) throws SystemException {
4251                    FinderPath finderPath = null;
4252                    Object[] finderArgs = null;
4253    
4254                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4255                                    (orderByComparator == null)) {
4256                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4257                            finderArgs = new Object[] { groupId, userId };
4258                    }
4259                    else {
4260                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4261                            finderArgs = new Object[] {
4262                                            groupId, userId,
4263                                            
4264                                            start, end, orderByComparator
4265                                    };
4266                    }
4267    
4268                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4269                                    finderArgs, this);
4270    
4271                    if (list == null) {
4272                            StringBundler query = null;
4273    
4274                            if (orderByComparator != null) {
4275                                    query = new StringBundler(4 +
4276                                                    (orderByComparator.getOrderByFields().length * 3));
4277                            }
4278                            else {
4279                                    query = new StringBundler(4);
4280                            }
4281    
4282                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4283    
4284                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4285    
4286                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4287    
4288                            if (orderByComparator != null) {
4289                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4290                                            orderByComparator);
4291                            }
4292    
4293                            else {
4294                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4295                            }
4296    
4297                            String sql = query.toString();
4298    
4299                            Session session = null;
4300    
4301                            try {
4302                                    session = openSession();
4303    
4304                                    Query q = session.createQuery(sql);
4305    
4306                                    QueryPos qPos = QueryPos.getInstance(q);
4307    
4308                                    qPos.add(groupId);
4309    
4310                                    qPos.add(userId);
4311    
4312                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
4313                                                    end);
4314                            }
4315                            catch (Exception e) {
4316                                    throw processException(e);
4317                            }
4318                            finally {
4319                                    if (list == null) {
4320                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4321                                    }
4322                                    else {
4323                                            cacheResult(list);
4324    
4325                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4326                                    }
4327    
4328                                    closeSession(session);
4329                            }
4330                    }
4331    
4332                    return list;
4333            }
4334    
4335            /**
4336             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4337             *
4338             * <p>
4339             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4340             * </p>
4341             *
4342             * @param groupId the group ID
4343             * @param userId the user ID
4344             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4345             * @return the first matching message-boards message
4346             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4347             * @throws SystemException if a system exception occurred
4348             */
4349            public MBMessage findByG_U_First(long groupId, long userId,
4350                    OrderByComparator orderByComparator)
4351                    throws NoSuchMessageException, SystemException {
4352                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4353                                    orderByComparator);
4354    
4355                    if (list.isEmpty()) {
4356                            StringBundler msg = new StringBundler(6);
4357    
4358                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4359    
4360                            msg.append("groupId=");
4361                            msg.append(groupId);
4362    
4363                            msg.append(", userId=");
4364                            msg.append(userId);
4365    
4366                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4367    
4368                            throw new NoSuchMessageException(msg.toString());
4369                    }
4370                    else {
4371                            return list.get(0);
4372                    }
4373            }
4374    
4375            /**
4376             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4377             *
4378             * <p>
4379             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4380             * </p>
4381             *
4382             * @param groupId the group ID
4383             * @param userId the user ID
4384             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4385             * @return the last matching message-boards message
4386             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4387             * @throws SystemException if a system exception occurred
4388             */
4389            public MBMessage findByG_U_Last(long groupId, long userId,
4390                    OrderByComparator orderByComparator)
4391                    throws NoSuchMessageException, SystemException {
4392                    int count = countByG_U(groupId, userId);
4393    
4394                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4395                                    orderByComparator);
4396    
4397                    if (list.isEmpty()) {
4398                            StringBundler msg = new StringBundler(6);
4399    
4400                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4401    
4402                            msg.append("groupId=");
4403                            msg.append(groupId);
4404    
4405                            msg.append(", userId=");
4406                            msg.append(userId);
4407    
4408                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4409    
4410                            throw new NoSuchMessageException(msg.toString());
4411                    }
4412                    else {
4413                            return list.get(0);
4414                    }
4415            }
4416    
4417            /**
4418             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4419             *
4420             * <p>
4421             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4422             * </p>
4423             *
4424             * @param messageId the primary key of the current message-boards message
4425             * @param groupId the group ID
4426             * @param userId the user ID
4427             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4428             * @return the previous, current, and next message-boards message
4429             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4430             * @throws SystemException if a system exception occurred
4431             */
4432            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4433                    long userId, OrderByComparator orderByComparator)
4434                    throws NoSuchMessageException, SystemException {
4435                    MBMessage mbMessage = findByPrimaryKey(messageId);
4436    
4437                    Session session = null;
4438    
4439                    try {
4440                            session = openSession();
4441    
4442                            MBMessage[] array = new MBMessageImpl[3];
4443    
4444                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4445                                            userId, orderByComparator, true);
4446    
4447                            array[1] = mbMessage;
4448    
4449                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4450                                            userId, orderByComparator, false);
4451    
4452                            return array;
4453                    }
4454                    catch (Exception e) {
4455                            throw processException(e);
4456                    }
4457                    finally {
4458                            closeSession(session);
4459                    }
4460            }
4461    
4462            protected MBMessage getByG_U_PrevAndNext(Session session,
4463                    MBMessage mbMessage, long groupId, long userId,
4464                    OrderByComparator orderByComparator, boolean previous) {
4465                    StringBundler query = null;
4466    
4467                    if (orderByComparator != null) {
4468                            query = new StringBundler(6 +
4469                                            (orderByComparator.getOrderByFields().length * 6));
4470                    }
4471                    else {
4472                            query = new StringBundler(3);
4473                    }
4474    
4475                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4476    
4477                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4478    
4479                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4480    
4481                    if (orderByComparator != null) {
4482                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4483    
4484                            if (orderByConditionFields.length > 0) {
4485                                    query.append(WHERE_AND);
4486                            }
4487    
4488                            for (int i = 0; i < orderByConditionFields.length; i++) {
4489                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4490                                    query.append(orderByConditionFields[i]);
4491    
4492                                    if ((i + 1) < orderByConditionFields.length) {
4493                                            if (orderByComparator.isAscending() ^ previous) {
4494                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4495                                            }
4496                                            else {
4497                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4498                                            }
4499                                    }
4500                                    else {
4501                                            if (orderByComparator.isAscending() ^ previous) {
4502                                                    query.append(WHERE_GREATER_THAN);
4503                                            }
4504                                            else {
4505                                                    query.append(WHERE_LESSER_THAN);
4506                                            }
4507                                    }
4508                            }
4509    
4510                            query.append(ORDER_BY_CLAUSE);
4511    
4512                            String[] orderByFields = orderByComparator.getOrderByFields();
4513    
4514                            for (int i = 0; i < orderByFields.length; i++) {
4515                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4516                                    query.append(orderByFields[i]);
4517    
4518                                    if ((i + 1) < orderByFields.length) {
4519                                            if (orderByComparator.isAscending() ^ previous) {
4520                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4521                                            }
4522                                            else {
4523                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4524                                            }
4525                                    }
4526                                    else {
4527                                            if (orderByComparator.isAscending() ^ previous) {
4528                                                    query.append(ORDER_BY_ASC);
4529                                            }
4530                                            else {
4531                                                    query.append(ORDER_BY_DESC);
4532                                            }
4533                                    }
4534                            }
4535                    }
4536    
4537                    else {
4538                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4539                    }
4540    
4541                    String sql = query.toString();
4542    
4543                    Query q = session.createQuery(sql);
4544    
4545                    q.setFirstResult(0);
4546                    q.setMaxResults(2);
4547    
4548                    QueryPos qPos = QueryPos.getInstance(q);
4549    
4550                    qPos.add(groupId);
4551    
4552                    qPos.add(userId);
4553    
4554                    if (orderByComparator != null) {
4555                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4556    
4557                            for (Object value : values) {
4558                                    qPos.add(value);
4559                            }
4560                    }
4561    
4562                    List<MBMessage> list = q.list();
4563    
4564                    if (list.size() == 2) {
4565                            return list.get(1);
4566                    }
4567                    else {
4568                            return null;
4569                    }
4570            }
4571    
4572            /**
4573             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4574             *
4575             * @param groupId the group ID
4576             * @param userId the user ID
4577             * @return the matching message-boards messages that the user has permission to view
4578             * @throws SystemException if a system exception occurred
4579             */
4580            public List<MBMessage> filterFindByG_U(long groupId, long userId)
4581                    throws SystemException {
4582                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4583                            QueryUtil.ALL_POS, null);
4584            }
4585    
4586            /**
4587             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4588             *
4589             * <p>
4590             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4591             * </p>
4592             *
4593             * @param groupId the group ID
4594             * @param userId the user ID
4595             * @param start the lower bound of the range of message-boards messages
4596             * @param end the upper bound of the range of message-boards messages (not inclusive)
4597             * @return the range of matching message-boards messages that the user has permission to view
4598             * @throws SystemException if a system exception occurred
4599             */
4600            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4601                    int start, int end) throws SystemException {
4602                    return filterFindByG_U(groupId, userId, start, end, null);
4603            }
4604    
4605            /**
4606             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
4607             *
4608             * <p>
4609             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4610             * </p>
4611             *
4612             * @param groupId the group ID
4613             * @param userId the user ID
4614             * @param start the lower bound of the range of message-boards messages
4615             * @param end the upper bound of the range of message-boards messages (not inclusive)
4616             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4617             * @return the ordered range of matching message-boards messages that the user has permission to view
4618             * @throws SystemException if a system exception occurred
4619             */
4620            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4621                    int start, int end, OrderByComparator orderByComparator)
4622                    throws SystemException {
4623                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4624                            return findByG_U(groupId, userId, start, end, orderByComparator);
4625                    }
4626    
4627                    StringBundler query = null;
4628    
4629                    if (orderByComparator != null) {
4630                            query = new StringBundler(4 +
4631                                            (orderByComparator.getOrderByFields().length * 3));
4632                    }
4633                    else {
4634                            query = new StringBundler(4);
4635                    }
4636    
4637                    if (getDB().isSupportsInlineDistinct()) {
4638                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4639                    }
4640                    else {
4641                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4642                    }
4643    
4644                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4645    
4646                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4647    
4648                    if (!getDB().isSupportsInlineDistinct()) {
4649                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4650                    }
4651    
4652                    if (orderByComparator != null) {
4653                            if (getDB().isSupportsInlineDistinct()) {
4654                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4655                                            orderByComparator);
4656                            }
4657                            else {
4658                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4659                                            orderByComparator);
4660                            }
4661                    }
4662    
4663                    else {
4664                            if (getDB().isSupportsInlineDistinct()) {
4665                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4666                            }
4667                            else {
4668                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4669                            }
4670                    }
4671    
4672                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4673                                    MBMessage.class.getName(),
4674                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4675    
4676                    Session session = null;
4677    
4678                    try {
4679                            session = openSession();
4680    
4681                            SQLQuery q = session.createSQLQuery(sql);
4682    
4683                            if (getDB().isSupportsInlineDistinct()) {
4684                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4685                            }
4686                            else {
4687                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4688                            }
4689    
4690                            QueryPos qPos = QueryPos.getInstance(q);
4691    
4692                            qPos.add(groupId);
4693    
4694                            qPos.add(userId);
4695    
4696                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4697                    }
4698                    catch (Exception e) {
4699                            throw processException(e);
4700                    }
4701                    finally {
4702                            closeSession(session);
4703                    }
4704            }
4705    
4706            /**
4707             * 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;.
4708             *
4709             * @param messageId the primary key of the current message-boards message
4710             * @param groupId the group ID
4711             * @param userId the user ID
4712             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4713             * @return the previous, current, and next message-boards message
4714             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4715             * @throws SystemException if a system exception occurred
4716             */
4717            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4718                    long groupId, long userId, OrderByComparator orderByComparator)
4719                    throws NoSuchMessageException, SystemException {
4720                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4721                            return findByG_U_PrevAndNext(messageId, groupId, userId,
4722                                    orderByComparator);
4723                    }
4724    
4725                    MBMessage mbMessage = findByPrimaryKey(messageId);
4726    
4727                    Session session = null;
4728    
4729                    try {
4730                            session = openSession();
4731    
4732                            MBMessage[] array = new MBMessageImpl[3];
4733    
4734                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4735                                            userId, orderByComparator, true);
4736    
4737                            array[1] = mbMessage;
4738    
4739                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4740                                            userId, orderByComparator, false);
4741    
4742                            return array;
4743                    }
4744                    catch (Exception e) {
4745                            throw processException(e);
4746                    }
4747                    finally {
4748                            closeSession(session);
4749                    }
4750            }
4751    
4752            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
4753                    MBMessage mbMessage, long groupId, long userId,
4754                    OrderByComparator orderByComparator, boolean previous) {
4755                    StringBundler query = null;
4756    
4757                    if (orderByComparator != null) {
4758                            query = new StringBundler(6 +
4759                                            (orderByComparator.getOrderByFields().length * 6));
4760                    }
4761                    else {
4762                            query = new StringBundler(3);
4763                    }
4764    
4765                    if (getDB().isSupportsInlineDistinct()) {
4766                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4767                    }
4768                    else {
4769                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4770                    }
4771    
4772                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4773    
4774                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4775    
4776                    if (!getDB().isSupportsInlineDistinct()) {
4777                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4778                    }
4779    
4780                    if (orderByComparator != null) {
4781                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4782    
4783                            if (orderByConditionFields.length > 0) {
4784                                    query.append(WHERE_AND);
4785                            }
4786    
4787                            for (int i = 0; i < orderByConditionFields.length; i++) {
4788                                    if (getDB().isSupportsInlineDistinct()) {
4789                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4790                                    }
4791                                    else {
4792                                            query.append(_ORDER_BY_ENTITY_TABLE);
4793                                    }
4794    
4795                                    query.append(orderByConditionFields[i]);
4796    
4797                                    if ((i + 1) < orderByConditionFields.length) {
4798                                            if (orderByComparator.isAscending() ^ previous) {
4799                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4800                                            }
4801                                            else {
4802                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4803                                            }
4804                                    }
4805                                    else {
4806                                            if (orderByComparator.isAscending() ^ previous) {
4807                                                    query.append(WHERE_GREATER_THAN);
4808                                            }
4809                                            else {
4810                                                    query.append(WHERE_LESSER_THAN);
4811                                            }
4812                                    }
4813                            }
4814    
4815                            query.append(ORDER_BY_CLAUSE);
4816    
4817                            String[] orderByFields = orderByComparator.getOrderByFields();
4818    
4819                            for (int i = 0; i < orderByFields.length; i++) {
4820                                    if (getDB().isSupportsInlineDistinct()) {
4821                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4822                                    }
4823                                    else {
4824                                            query.append(_ORDER_BY_ENTITY_TABLE);
4825                                    }
4826    
4827                                    query.append(orderByFields[i]);
4828    
4829                                    if ((i + 1) < orderByFields.length) {
4830                                            if (orderByComparator.isAscending() ^ previous) {
4831                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4832                                            }
4833                                            else {
4834                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4835                                            }
4836                                    }
4837                                    else {
4838                                            if (orderByComparator.isAscending() ^ previous) {
4839                                                    query.append(ORDER_BY_ASC);
4840                                            }
4841                                            else {
4842                                                    query.append(ORDER_BY_DESC);
4843                                            }
4844                                    }
4845                            }
4846                    }
4847    
4848                    else {
4849                            if (getDB().isSupportsInlineDistinct()) {
4850                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4851                            }
4852                            else {
4853                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4854                            }
4855                    }
4856    
4857                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4858                                    MBMessage.class.getName(),
4859                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4860    
4861                    SQLQuery q = session.createSQLQuery(sql);
4862    
4863                    q.setFirstResult(0);
4864                    q.setMaxResults(2);
4865    
4866                    if (getDB().isSupportsInlineDistinct()) {
4867                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4868                    }
4869                    else {
4870                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4871                    }
4872    
4873                    QueryPos qPos = QueryPos.getInstance(q);
4874    
4875                    qPos.add(groupId);
4876    
4877                    qPos.add(userId);
4878    
4879                    if (orderByComparator != null) {
4880                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4881    
4882                            for (Object value : values) {
4883                                    qPos.add(value);
4884                            }
4885                    }
4886    
4887                    List<MBMessage> list = q.list();
4888    
4889                    if (list.size() == 2) {
4890                            return list.get(1);
4891                    }
4892                    else {
4893                            return null;
4894                    }
4895            }
4896    
4897            /**
4898             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
4899             *
4900             * @param groupId the group ID
4901             * @param categoryId the category ID
4902             * @return the matching message-boards messages
4903             * @throws SystemException if a system exception occurred
4904             */
4905            public List<MBMessage> findByG_C(long groupId, long categoryId)
4906                    throws SystemException {
4907                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
4908                            QueryUtil.ALL_POS, null);
4909            }
4910    
4911            /**
4912             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
4913             *
4914             * <p>
4915             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4916             * </p>
4917             *
4918             * @param groupId the group ID
4919             * @param categoryId the category ID
4920             * @param start the lower bound of the range of message-boards messages
4921             * @param end the upper bound of the range of message-boards messages (not inclusive)
4922             * @return the range of matching message-boards messages
4923             * @throws SystemException if a system exception occurred
4924             */
4925            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
4926                    int end) throws SystemException {
4927                    return findByG_C(groupId, categoryId, start, end, null);
4928            }
4929    
4930            /**
4931             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
4932             *
4933             * <p>
4934             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4935             * </p>
4936             *
4937             * @param groupId the group ID
4938             * @param categoryId the category ID
4939             * @param start the lower bound of the range of message-boards messages
4940             * @param end the upper bound of the range of message-boards messages (not inclusive)
4941             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4942             * @return the ordered range of matching message-boards messages
4943             * @throws SystemException if a system exception occurred
4944             */
4945            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
4946                    int end, OrderByComparator orderByComparator) throws SystemException {
4947                    FinderPath finderPath = null;
4948                    Object[] finderArgs = null;
4949    
4950                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4951                                    (orderByComparator == null)) {
4952                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
4953                            finderArgs = new Object[] { groupId, categoryId };
4954                    }
4955                    else {
4956                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
4957                            finderArgs = new Object[] {
4958                                            groupId, categoryId,
4959                                            
4960                                            start, end, orderByComparator
4961                                    };
4962                    }
4963    
4964                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4965                                    finderArgs, this);
4966    
4967                    if (list == null) {
4968                            StringBundler query = null;
4969    
4970                            if (orderByComparator != null) {
4971                                    query = new StringBundler(4 +
4972                                                    (orderByComparator.getOrderByFields().length * 3));
4973                            }
4974                            else {
4975                                    query = new StringBundler(4);
4976                            }
4977    
4978                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4979    
4980                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
4981    
4982                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
4983    
4984                            if (orderByComparator != null) {
4985                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4986                                            orderByComparator);
4987                            }
4988    
4989                            else {
4990                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4991                            }
4992    
4993                            String sql = query.toString();
4994    
4995                            Session session = null;
4996    
4997                            try {
4998                                    session = openSession();
4999    
5000                                    Query q = session.createQuery(sql);
5001    
5002                                    QueryPos qPos = QueryPos.getInstance(q);
5003    
5004                                    qPos.add(groupId);
5005    
5006                                    qPos.add(categoryId);
5007    
5008                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
5009                                                    end);
5010                            }
5011                            catch (Exception e) {
5012                                    throw processException(e);
5013                            }
5014                            finally {
5015                                    if (list == null) {
5016                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
5017                                    }
5018                                    else {
5019                                            cacheResult(list);
5020    
5021                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
5022                                    }
5023    
5024                                    closeSession(session);
5025                            }
5026                    }
5027    
5028                    return list;
5029            }
5030    
5031            /**
5032             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5033             *
5034             * <p>
5035             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5036             * </p>
5037             *
5038             * @param groupId the group ID
5039             * @param categoryId the category ID
5040             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5041             * @return the first matching message-boards message
5042             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5043             * @throws SystemException if a system exception occurred
5044             */
5045            public MBMessage findByG_C_First(long groupId, long categoryId,
5046                    OrderByComparator orderByComparator)
5047                    throws NoSuchMessageException, SystemException {
5048                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5049                                    orderByComparator);
5050    
5051                    if (list.isEmpty()) {
5052                            StringBundler msg = new StringBundler(6);
5053    
5054                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5055    
5056                            msg.append("groupId=");
5057                            msg.append(groupId);
5058    
5059                            msg.append(", categoryId=");
5060                            msg.append(categoryId);
5061    
5062                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5063    
5064                            throw new NoSuchMessageException(msg.toString());
5065                    }
5066                    else {
5067                            return list.get(0);
5068                    }
5069            }
5070    
5071            /**
5072             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5073             *
5074             * <p>
5075             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5076             * </p>
5077             *
5078             * @param groupId the group ID
5079             * @param categoryId the category ID
5080             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5081             * @return the last matching message-boards message
5082             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5083             * @throws SystemException if a system exception occurred
5084             */
5085            public MBMessage findByG_C_Last(long groupId, long categoryId,
5086                    OrderByComparator orderByComparator)
5087                    throws NoSuchMessageException, SystemException {
5088                    int count = countByG_C(groupId, categoryId);
5089    
5090                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5091                                    orderByComparator);
5092    
5093                    if (list.isEmpty()) {
5094                            StringBundler msg = new StringBundler(6);
5095    
5096                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5097    
5098                            msg.append("groupId=");
5099                            msg.append(groupId);
5100    
5101                            msg.append(", categoryId=");
5102                            msg.append(categoryId);
5103    
5104                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5105    
5106                            throw new NoSuchMessageException(msg.toString());
5107                    }
5108                    else {
5109                            return list.get(0);
5110                    }
5111            }
5112    
5113            /**
5114             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5115             *
5116             * <p>
5117             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5118             * </p>
5119             *
5120             * @param messageId the primary key of the current message-boards message
5121             * @param groupId the group ID
5122             * @param categoryId the category ID
5123             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5124             * @return the previous, current, and next message-boards message
5125             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5126             * @throws SystemException if a system exception occurred
5127             */
5128            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5129                    long categoryId, OrderByComparator orderByComparator)
5130                    throws NoSuchMessageException, SystemException {
5131                    MBMessage mbMessage = findByPrimaryKey(messageId);
5132    
5133                    Session session = null;
5134    
5135                    try {
5136                            session = openSession();
5137    
5138                            MBMessage[] array = new MBMessageImpl[3];
5139    
5140                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5141                                            categoryId, orderByComparator, true);
5142    
5143                            array[1] = mbMessage;
5144    
5145                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5146                                            categoryId, orderByComparator, false);
5147    
5148                            return array;
5149                    }
5150                    catch (Exception e) {
5151                            throw processException(e);
5152                    }
5153                    finally {
5154                            closeSession(session);
5155                    }
5156            }
5157    
5158            protected MBMessage getByG_C_PrevAndNext(Session session,
5159                    MBMessage mbMessage, long groupId, long categoryId,
5160                    OrderByComparator orderByComparator, boolean previous) {
5161                    StringBundler query = null;
5162    
5163                    if (orderByComparator != null) {
5164                            query = new StringBundler(6 +
5165                                            (orderByComparator.getOrderByFields().length * 6));
5166                    }
5167                    else {
5168                            query = new StringBundler(3);
5169                    }
5170    
5171                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5172    
5173                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5174    
5175                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5176    
5177                    if (orderByComparator != null) {
5178                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5179    
5180                            if (orderByConditionFields.length > 0) {
5181                                    query.append(WHERE_AND);
5182                            }
5183    
5184                            for (int i = 0; i < orderByConditionFields.length; i++) {
5185                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5186                                    query.append(orderByConditionFields[i]);
5187    
5188                                    if ((i + 1) < orderByConditionFields.length) {
5189                                            if (orderByComparator.isAscending() ^ previous) {
5190                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5191                                            }
5192                                            else {
5193                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5194                                            }
5195                                    }
5196                                    else {
5197                                            if (orderByComparator.isAscending() ^ previous) {
5198                                                    query.append(WHERE_GREATER_THAN);
5199                                            }
5200                                            else {
5201                                                    query.append(WHERE_LESSER_THAN);
5202                                            }
5203                                    }
5204                            }
5205    
5206                            query.append(ORDER_BY_CLAUSE);
5207    
5208                            String[] orderByFields = orderByComparator.getOrderByFields();
5209    
5210                            for (int i = 0; i < orderByFields.length; i++) {
5211                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5212                                    query.append(orderByFields[i]);
5213    
5214                                    if ((i + 1) < orderByFields.length) {
5215                                            if (orderByComparator.isAscending() ^ previous) {
5216                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5217                                            }
5218                                            else {
5219                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5220                                            }
5221                                    }
5222                                    else {
5223                                            if (orderByComparator.isAscending() ^ previous) {
5224                                                    query.append(ORDER_BY_ASC);
5225                                            }
5226                                            else {
5227                                                    query.append(ORDER_BY_DESC);
5228                                            }
5229                                    }
5230                            }
5231                    }
5232    
5233                    else {
5234                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5235                    }
5236    
5237                    String sql = query.toString();
5238    
5239                    Query q = session.createQuery(sql);
5240    
5241                    q.setFirstResult(0);
5242                    q.setMaxResults(2);
5243    
5244                    QueryPos qPos = QueryPos.getInstance(q);
5245    
5246                    qPos.add(groupId);
5247    
5248                    qPos.add(categoryId);
5249    
5250                    if (orderByComparator != null) {
5251                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5252    
5253                            for (Object value : values) {
5254                                    qPos.add(value);
5255                            }
5256                    }
5257    
5258                    List<MBMessage> list = q.list();
5259    
5260                    if (list.size() == 2) {
5261                            return list.get(1);
5262                    }
5263                    else {
5264                            return null;
5265                    }
5266            }
5267    
5268            /**
5269             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5270             *
5271             * @param groupId the group ID
5272             * @param categoryId the category ID
5273             * @return the matching message-boards messages that the user has permission to view
5274             * @throws SystemException if a system exception occurred
5275             */
5276            public List<MBMessage> filterFindByG_C(long groupId, long categoryId)
5277                    throws SystemException {
5278                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5279                            QueryUtil.ALL_POS, null);
5280            }
5281    
5282            /**
5283             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5284             *
5285             * <p>
5286             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5287             * </p>
5288             *
5289             * @param groupId the group ID
5290             * @param categoryId the category ID
5291             * @param start the lower bound of the range of message-boards messages
5292             * @param end the upper bound of the range of message-boards messages (not inclusive)
5293             * @return the range of matching message-boards messages that the user has permission to view
5294             * @throws SystemException if a system exception occurred
5295             */
5296            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5297                    int start, int end) throws SystemException {
5298                    return filterFindByG_C(groupId, categoryId, start, end, null);
5299            }
5300    
5301            /**
5302             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
5303             *
5304             * <p>
5305             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5306             * </p>
5307             *
5308             * @param groupId the group ID
5309             * @param categoryId the category ID
5310             * @param start the lower bound of the range of message-boards messages
5311             * @param end the upper bound of the range of message-boards messages (not inclusive)
5312             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5313             * @return the ordered range of matching message-boards messages that the user has permission to view
5314             * @throws SystemException if a system exception occurred
5315             */
5316            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5317                    int start, int end, OrderByComparator orderByComparator)
5318                    throws SystemException {
5319                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5320                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
5321                    }
5322    
5323                    StringBundler query = null;
5324    
5325                    if (orderByComparator != null) {
5326                            query = new StringBundler(4 +
5327                                            (orderByComparator.getOrderByFields().length * 3));
5328                    }
5329                    else {
5330                            query = new StringBundler(4);
5331                    }
5332    
5333                    if (getDB().isSupportsInlineDistinct()) {
5334                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5335                    }
5336                    else {
5337                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5338                    }
5339    
5340                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5341    
5342                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5343    
5344                    if (!getDB().isSupportsInlineDistinct()) {
5345                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5346                    }
5347    
5348                    if (orderByComparator != null) {
5349                            if (getDB().isSupportsInlineDistinct()) {
5350                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5351                                            orderByComparator);
5352                            }
5353                            else {
5354                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5355                                            orderByComparator);
5356                            }
5357                    }
5358    
5359                    else {
5360                            if (getDB().isSupportsInlineDistinct()) {
5361                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5362                            }
5363                            else {
5364                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5365                            }
5366                    }
5367    
5368                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5369                                    MBMessage.class.getName(),
5370                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5371    
5372                    Session session = null;
5373    
5374                    try {
5375                            session = openSession();
5376    
5377                            SQLQuery q = session.createSQLQuery(sql);
5378    
5379                            if (getDB().isSupportsInlineDistinct()) {
5380                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5381                            }
5382                            else {
5383                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5384                            }
5385    
5386                            QueryPos qPos = QueryPos.getInstance(q);
5387    
5388                            qPos.add(groupId);
5389    
5390                            qPos.add(categoryId);
5391    
5392                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5393                    }
5394                    catch (Exception e) {
5395                            throw processException(e);
5396                    }
5397                    finally {
5398                            closeSession(session);
5399                    }
5400            }
5401    
5402            /**
5403             * 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;.
5404             *
5405             * @param messageId the primary key of the current message-boards message
5406             * @param groupId the group ID
5407             * @param categoryId the category ID
5408             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5409             * @return the previous, current, and next message-boards message
5410             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5411             * @throws SystemException if a system exception occurred
5412             */
5413            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5414                    long groupId, long categoryId, OrderByComparator orderByComparator)
5415                    throws NoSuchMessageException, SystemException {
5416                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5417                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5418                                    orderByComparator);
5419                    }
5420    
5421                    MBMessage mbMessage = findByPrimaryKey(messageId);
5422    
5423                    Session session = null;
5424    
5425                    try {
5426                            session = openSession();
5427    
5428                            MBMessage[] array = new MBMessageImpl[3];
5429    
5430                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5431                                            categoryId, orderByComparator, true);
5432    
5433                            array[1] = mbMessage;
5434    
5435                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5436                                            categoryId, orderByComparator, false);
5437    
5438                            return array;
5439                    }
5440                    catch (Exception e) {
5441                            throw processException(e);
5442                    }
5443                    finally {
5444                            closeSession(session);
5445                    }
5446            }
5447    
5448            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5449                    MBMessage mbMessage, long groupId, long categoryId,
5450                    OrderByComparator orderByComparator, boolean previous) {
5451                    StringBundler query = null;
5452    
5453                    if (orderByComparator != null) {
5454                            query = new StringBundler(6 +
5455                                            (orderByComparator.getOrderByFields().length * 6));
5456                    }
5457                    else {
5458                            query = new StringBundler(3);
5459                    }
5460    
5461                    if (getDB().isSupportsInlineDistinct()) {
5462                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5463                    }
5464                    else {
5465                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5466                    }
5467    
5468                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5469    
5470                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5471    
5472                    if (!getDB().isSupportsInlineDistinct()) {
5473                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5474                    }
5475    
5476                    if (orderByComparator != null) {
5477                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5478    
5479                            if (orderByConditionFields.length > 0) {
5480                                    query.append(WHERE_AND);
5481                            }
5482    
5483                            for (int i = 0; i < orderByConditionFields.length; i++) {
5484                                    if (getDB().isSupportsInlineDistinct()) {
5485                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5486                                    }
5487                                    else {
5488                                            query.append(_ORDER_BY_ENTITY_TABLE);
5489                                    }
5490    
5491                                    query.append(orderByConditionFields[i]);
5492    
5493                                    if ((i + 1) < orderByConditionFields.length) {
5494                                            if (orderByComparator.isAscending() ^ previous) {
5495                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5496                                            }
5497                                            else {
5498                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5499                                            }
5500                                    }
5501                                    else {
5502                                            if (orderByComparator.isAscending() ^ previous) {
5503                                                    query.append(WHERE_GREATER_THAN);
5504                                            }
5505                                            else {
5506                                                    query.append(WHERE_LESSER_THAN);
5507                                            }
5508                                    }
5509                            }
5510    
5511                            query.append(ORDER_BY_CLAUSE);
5512    
5513                            String[] orderByFields = orderByComparator.getOrderByFields();
5514    
5515                            for (int i = 0; i < orderByFields.length; i++) {
5516                                    if (getDB().isSupportsInlineDistinct()) {
5517                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5518                                    }
5519                                    else {
5520                                            query.append(_ORDER_BY_ENTITY_TABLE);
5521                                    }
5522    
5523                                    query.append(orderByFields[i]);
5524    
5525                                    if ((i + 1) < orderByFields.length) {
5526                                            if (orderByComparator.isAscending() ^ previous) {
5527                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5528                                            }
5529                                            else {
5530                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5531                                            }
5532                                    }
5533                                    else {
5534                                            if (orderByComparator.isAscending() ^ previous) {
5535                                                    query.append(ORDER_BY_ASC);
5536                                            }
5537                                            else {
5538                                                    query.append(ORDER_BY_DESC);
5539                                            }
5540                                    }
5541                            }
5542                    }
5543    
5544                    else {
5545                            if (getDB().isSupportsInlineDistinct()) {
5546                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5547                            }
5548                            else {
5549                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5550                            }
5551                    }
5552    
5553                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5554                                    MBMessage.class.getName(),
5555                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5556    
5557                    SQLQuery q = session.createSQLQuery(sql);
5558    
5559                    q.setFirstResult(0);
5560                    q.setMaxResults(2);
5561    
5562                    if (getDB().isSupportsInlineDistinct()) {
5563                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5564                    }
5565                    else {
5566                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5567                    }
5568    
5569                    QueryPos qPos = QueryPos.getInstance(q);
5570    
5571                    qPos.add(groupId);
5572    
5573                    qPos.add(categoryId);
5574    
5575                    if (orderByComparator != null) {
5576                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5577    
5578                            for (Object value : values) {
5579                                    qPos.add(value);
5580                            }
5581                    }
5582    
5583                    List<MBMessage> list = q.list();
5584    
5585                    if (list.size() == 2) {
5586                            return list.get(1);
5587                    }
5588                    else {
5589                            return null;
5590                    }
5591            }
5592    
5593            /**
5594             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
5595             *
5596             * @param groupId the group ID
5597             * @param status the status
5598             * @return the matching message-boards messages
5599             * @throws SystemException if a system exception occurred
5600             */
5601            public List<MBMessage> findByG_S(long groupId, int status)
5602                    throws SystemException {
5603                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5604                            null);
5605            }
5606    
5607            /**
5608             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
5609             *
5610             * <p>
5611             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5612             * </p>
5613             *
5614             * @param groupId the group ID
5615             * @param status the status
5616             * @param start the lower bound of the range of message-boards messages
5617             * @param end the upper bound of the range of message-boards messages (not inclusive)
5618             * @return the range of matching message-boards messages
5619             * @throws SystemException if a system exception occurred
5620             */
5621            public List<MBMessage> findByG_S(long groupId, int status, int start,
5622                    int end) throws SystemException {
5623                    return findByG_S(groupId, status, start, end, null);
5624            }
5625    
5626            /**
5627             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
5628             *
5629             * <p>
5630             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5631             * </p>
5632             *
5633             * @param groupId the group ID
5634             * @param status the status
5635             * @param start the lower bound of the range of message-boards messages
5636             * @param end the upper bound of the range of message-boards messages (not inclusive)
5637             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5638             * @return the ordered range of matching message-boards messages
5639             * @throws SystemException if a system exception occurred
5640             */
5641            public List<MBMessage> findByG_S(long groupId, int status, int start,
5642                    int end, OrderByComparator orderByComparator) throws SystemException {
5643                    FinderPath finderPath = null;
5644                    Object[] finderArgs = null;
5645    
5646                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5647                                    (orderByComparator == null)) {
5648                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
5649                            finderArgs = new Object[] { groupId, status };
5650                    }
5651                    else {
5652                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
5653                            finderArgs = new Object[] {
5654                                            groupId, status,
5655                                            
5656                                            start, end, orderByComparator
5657                                    };
5658                    }
5659    
5660                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
5661                                    finderArgs, this);
5662    
5663                    if (list == null) {
5664                            StringBundler query = null;
5665    
5666                            if (orderByComparator != null) {
5667                                    query = new StringBundler(4 +
5668                                                    (orderByComparator.getOrderByFields().length * 3));
5669                            }
5670                            else {
5671                                    query = new StringBundler(4);
5672                            }
5673    
5674                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5675    
5676                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5677    
5678                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
5679    
5680                            if (orderByComparator != null) {
5681                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5682                                            orderByComparator);
5683                            }
5684    
5685                            else {
5686                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5687                            }
5688    
5689                            String sql = query.toString();
5690    
5691                            Session session = null;
5692    
5693                            try {
5694                                    session = openSession();
5695    
5696                                    Query q = session.createQuery(sql);
5697    
5698                                    QueryPos qPos = QueryPos.getInstance(q);
5699    
5700                                    qPos.add(groupId);
5701    
5702                                    qPos.add(status);
5703    
5704                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
5705                                                    end);
5706                            }
5707                            catch (Exception e) {
5708                                    throw processException(e);
5709                            }
5710                            finally {
5711                                    if (list == null) {
5712                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
5713                                    }
5714                                    else {
5715                                            cacheResult(list);
5716    
5717                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
5718                                    }
5719    
5720                                    closeSession(session);
5721                            }
5722                    }
5723    
5724                    return list;
5725            }
5726    
5727            /**
5728             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
5729             *
5730             * <p>
5731             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5732             * </p>
5733             *
5734             * @param groupId the group ID
5735             * @param status the status
5736             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5737             * @return the first matching message-boards message
5738             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5739             * @throws SystemException if a system exception occurred
5740             */
5741            public MBMessage findByG_S_First(long groupId, int status,
5742                    OrderByComparator orderByComparator)
5743                    throws NoSuchMessageException, SystemException {
5744                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
5745                                    orderByComparator);
5746    
5747                    if (list.isEmpty()) {
5748                            StringBundler msg = new StringBundler(6);
5749    
5750                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5751    
5752                            msg.append("groupId=");
5753                            msg.append(groupId);
5754    
5755                            msg.append(", status=");
5756                            msg.append(status);
5757    
5758                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5759    
5760                            throw new NoSuchMessageException(msg.toString());
5761                    }
5762                    else {
5763                            return list.get(0);
5764                    }
5765            }
5766    
5767            /**
5768             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
5769             *
5770             * <p>
5771             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5772             * </p>
5773             *
5774             * @param groupId the group ID
5775             * @param status the status
5776             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5777             * @return the last matching message-boards message
5778             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5779             * @throws SystemException if a system exception occurred
5780             */
5781            public MBMessage findByG_S_Last(long groupId, int status,
5782                    OrderByComparator orderByComparator)
5783                    throws NoSuchMessageException, SystemException {
5784                    int count = countByG_S(groupId, status);
5785    
5786                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
5787                                    orderByComparator);
5788    
5789                    if (list.isEmpty()) {
5790                            StringBundler msg = new StringBundler(6);
5791    
5792                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5793    
5794                            msg.append("groupId=");
5795                            msg.append(groupId);
5796    
5797                            msg.append(", status=");
5798                            msg.append(status);
5799    
5800                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5801    
5802                            throw new NoSuchMessageException(msg.toString());
5803                    }
5804                    else {
5805                            return list.get(0);
5806                    }
5807            }
5808    
5809            /**
5810             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
5811             *
5812             * <p>
5813             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5814             * </p>
5815             *
5816             * @param messageId the primary key of the current message-boards message
5817             * @param groupId the group ID
5818             * @param status the status
5819             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5820             * @return the previous, current, and next message-boards message
5821             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5822             * @throws SystemException if a system exception occurred
5823             */
5824            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
5825                    int status, OrderByComparator orderByComparator)
5826                    throws NoSuchMessageException, SystemException {
5827                    MBMessage mbMessage = findByPrimaryKey(messageId);
5828    
5829                    Session session = null;
5830    
5831                    try {
5832                            session = openSession();
5833    
5834                            MBMessage[] array = new MBMessageImpl[3];
5835    
5836                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
5837                                            status, orderByComparator, true);
5838    
5839                            array[1] = mbMessage;
5840    
5841                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
5842                                            status, orderByComparator, false);
5843    
5844                            return array;
5845                    }
5846                    catch (Exception e) {
5847                            throw processException(e);
5848                    }
5849                    finally {
5850                            closeSession(session);
5851                    }
5852            }
5853    
5854            protected MBMessage getByG_S_PrevAndNext(Session session,
5855                    MBMessage mbMessage, long groupId, int status,
5856                    OrderByComparator orderByComparator, boolean previous) {
5857                    StringBundler query = null;
5858    
5859                    if (orderByComparator != null) {
5860                            query = new StringBundler(6 +
5861                                            (orderByComparator.getOrderByFields().length * 6));
5862                    }
5863                    else {
5864                            query = new StringBundler(3);
5865                    }
5866    
5867                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5868    
5869                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5870    
5871                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
5872    
5873                    if (orderByComparator != null) {
5874                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5875    
5876                            if (orderByConditionFields.length > 0) {
5877                                    query.append(WHERE_AND);
5878                            }
5879    
5880                            for (int i = 0; i < orderByConditionFields.length; i++) {
5881                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5882                                    query.append(orderByConditionFields[i]);
5883    
5884                                    if ((i + 1) < orderByConditionFields.length) {
5885                                            if (orderByComparator.isAscending() ^ previous) {
5886                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5887                                            }
5888                                            else {
5889                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5890                                            }
5891                                    }
5892                                    else {
5893                                            if (orderByComparator.isAscending() ^ previous) {
5894                                                    query.append(WHERE_GREATER_THAN);
5895                                            }
5896                                            else {
5897                                                    query.append(WHERE_LESSER_THAN);
5898                                            }
5899                                    }
5900                            }
5901    
5902                            query.append(ORDER_BY_CLAUSE);
5903    
5904                            String[] orderByFields = orderByComparator.getOrderByFields();
5905    
5906                            for (int i = 0; i < orderByFields.length; i++) {
5907                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5908                                    query.append(orderByFields[i]);
5909    
5910                                    if ((i + 1) < orderByFields.length) {
5911                                            if (orderByComparator.isAscending() ^ previous) {
5912                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5913                                            }
5914                                            else {
5915                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5916                                            }
5917                                    }
5918                                    else {
5919                                            if (orderByComparator.isAscending() ^ previous) {
5920                                                    query.append(ORDER_BY_ASC);
5921                                            }
5922                                            else {
5923                                                    query.append(ORDER_BY_DESC);
5924                                            }
5925                                    }
5926                            }
5927                    }
5928    
5929                    else {
5930                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5931                    }
5932    
5933                    String sql = query.toString();
5934    
5935                    Query q = session.createQuery(sql);
5936    
5937                    q.setFirstResult(0);
5938                    q.setMaxResults(2);
5939    
5940                    QueryPos qPos = QueryPos.getInstance(q);
5941    
5942                    qPos.add(groupId);
5943    
5944                    qPos.add(status);
5945    
5946                    if (orderByComparator != null) {
5947                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5948    
5949                            for (Object value : values) {
5950                                    qPos.add(value);
5951                            }
5952                    }
5953    
5954                    List<MBMessage> list = q.list();
5955    
5956                    if (list.size() == 2) {
5957                            return list.get(1);
5958                    }
5959                    else {
5960                            return null;
5961                    }
5962            }
5963    
5964            /**
5965             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
5966             *
5967             * @param groupId the group ID
5968             * @param status the status
5969             * @return the matching message-boards messages that the user has permission to view
5970             * @throws SystemException if a system exception occurred
5971             */
5972            public List<MBMessage> filterFindByG_S(long groupId, int status)
5973                    throws SystemException {
5974                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
5975                            QueryUtil.ALL_POS, null);
5976            }
5977    
5978            /**
5979             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
5980             *
5981             * <p>
5982             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5983             * </p>
5984             *
5985             * @param groupId the group ID
5986             * @param status the status
5987             * @param start the lower bound of the range of message-boards messages
5988             * @param end the upper bound of the range of message-boards messages (not inclusive)
5989             * @return the range of matching message-boards messages that the user has permission to view
5990             * @throws SystemException if a system exception occurred
5991             */
5992            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
5993                    int end) throws SystemException {
5994                    return filterFindByG_S(groupId, status, start, end, null);
5995            }
5996    
5997            /**
5998             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
5999             *
6000             * <p>
6001             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6002             * </p>
6003             *
6004             * @param groupId the group ID
6005             * @param status the status
6006             * @param start the lower bound of the range of message-boards messages
6007             * @param end the upper bound of the range of message-boards messages (not inclusive)
6008             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6009             * @return the ordered range of matching message-boards messages that the user has permission to view
6010             * @throws SystemException if a system exception occurred
6011             */
6012            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6013                    int end, OrderByComparator orderByComparator) throws SystemException {
6014                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6015                            return findByG_S(groupId, status, start, end, orderByComparator);
6016                    }
6017    
6018                    StringBundler query = null;
6019    
6020                    if (orderByComparator != null) {
6021                            query = new StringBundler(4 +
6022                                            (orderByComparator.getOrderByFields().length * 3));
6023                    }
6024                    else {
6025                            query = new StringBundler(4);
6026                    }
6027    
6028                    if (getDB().isSupportsInlineDistinct()) {
6029                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6030                    }
6031                    else {
6032                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6033                    }
6034    
6035                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6036    
6037                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6038    
6039                    if (!getDB().isSupportsInlineDistinct()) {
6040                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6041                    }
6042    
6043                    if (orderByComparator != null) {
6044                            if (getDB().isSupportsInlineDistinct()) {
6045                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6046                                            orderByComparator);
6047                            }
6048                            else {
6049                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6050                                            orderByComparator);
6051                            }
6052                    }
6053    
6054                    else {
6055                            if (getDB().isSupportsInlineDistinct()) {
6056                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6057                            }
6058                            else {
6059                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6060                            }
6061                    }
6062    
6063                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6064                                    MBMessage.class.getName(),
6065                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6066    
6067                    Session session = null;
6068    
6069                    try {
6070                            session = openSession();
6071    
6072                            SQLQuery q = session.createSQLQuery(sql);
6073    
6074                            if (getDB().isSupportsInlineDistinct()) {
6075                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6076                            }
6077                            else {
6078                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6079                            }
6080    
6081                            QueryPos qPos = QueryPos.getInstance(q);
6082    
6083                            qPos.add(groupId);
6084    
6085                            qPos.add(status);
6086    
6087                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6088                    }
6089                    catch (Exception e) {
6090                            throw processException(e);
6091                    }
6092                    finally {
6093                            closeSession(session);
6094                    }
6095            }
6096    
6097            /**
6098             * 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;.
6099             *
6100             * @param messageId the primary key of the current message-boards message
6101             * @param groupId the group ID
6102             * @param status the status
6103             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6104             * @return the previous, current, and next message-boards message
6105             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6106             * @throws SystemException if a system exception occurred
6107             */
6108            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6109                    long groupId, int status, OrderByComparator orderByComparator)
6110                    throws NoSuchMessageException, SystemException {
6111                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6112                            return findByG_S_PrevAndNext(messageId, groupId, status,
6113                                    orderByComparator);
6114                    }
6115    
6116                    MBMessage mbMessage = findByPrimaryKey(messageId);
6117    
6118                    Session session = null;
6119    
6120                    try {
6121                            session = openSession();
6122    
6123                            MBMessage[] array = new MBMessageImpl[3];
6124    
6125                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6126                                            status, orderByComparator, true);
6127    
6128                            array[1] = mbMessage;
6129    
6130                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6131                                            status, orderByComparator, false);
6132    
6133                            return array;
6134                    }
6135                    catch (Exception e) {
6136                            throw processException(e);
6137                    }
6138                    finally {
6139                            closeSession(session);
6140                    }
6141            }
6142    
6143            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6144                    MBMessage mbMessage, long groupId, int status,
6145                    OrderByComparator orderByComparator, boolean previous) {
6146                    StringBundler query = null;
6147    
6148                    if (orderByComparator != null) {
6149                            query = new StringBundler(6 +
6150                                            (orderByComparator.getOrderByFields().length * 6));
6151                    }
6152                    else {
6153                            query = new StringBundler(3);
6154                    }
6155    
6156                    if (getDB().isSupportsInlineDistinct()) {
6157                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6158                    }
6159                    else {
6160                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6161                    }
6162    
6163                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6164    
6165                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6166    
6167                    if (!getDB().isSupportsInlineDistinct()) {
6168                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6169                    }
6170    
6171                    if (orderByComparator != null) {
6172                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6173    
6174                            if (orderByConditionFields.length > 0) {
6175                                    query.append(WHERE_AND);
6176                            }
6177    
6178                            for (int i = 0; i < orderByConditionFields.length; i++) {
6179                                    if (getDB().isSupportsInlineDistinct()) {
6180                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6181                                    }
6182                                    else {
6183                                            query.append(_ORDER_BY_ENTITY_TABLE);
6184                                    }
6185    
6186                                    query.append(orderByConditionFields[i]);
6187    
6188                                    if ((i + 1) < orderByConditionFields.length) {
6189                                            if (orderByComparator.isAscending() ^ previous) {
6190                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6191                                            }
6192                                            else {
6193                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6194                                            }
6195                                    }
6196                                    else {
6197                                            if (orderByComparator.isAscending() ^ previous) {
6198                                                    query.append(WHERE_GREATER_THAN);
6199                                            }
6200                                            else {
6201                                                    query.append(WHERE_LESSER_THAN);
6202                                            }
6203                                    }
6204                            }
6205    
6206                            query.append(ORDER_BY_CLAUSE);
6207    
6208                            String[] orderByFields = orderByComparator.getOrderByFields();
6209    
6210                            for (int i = 0; i < orderByFields.length; i++) {
6211                                    if (getDB().isSupportsInlineDistinct()) {
6212                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6213                                    }
6214                                    else {
6215                                            query.append(_ORDER_BY_ENTITY_TABLE);
6216                                    }
6217    
6218                                    query.append(orderByFields[i]);
6219    
6220                                    if ((i + 1) < orderByFields.length) {
6221                                            if (orderByComparator.isAscending() ^ previous) {
6222                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6223                                            }
6224                                            else {
6225                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6226                                            }
6227                                    }
6228                                    else {
6229                                            if (orderByComparator.isAscending() ^ previous) {
6230                                                    query.append(ORDER_BY_ASC);
6231                                            }
6232                                            else {
6233                                                    query.append(ORDER_BY_DESC);
6234                                            }
6235                                    }
6236                            }
6237                    }
6238    
6239                    else {
6240                            if (getDB().isSupportsInlineDistinct()) {
6241                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6242                            }
6243                            else {
6244                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6245                            }
6246                    }
6247    
6248                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6249                                    MBMessage.class.getName(),
6250                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6251    
6252                    SQLQuery q = session.createSQLQuery(sql);
6253    
6254                    q.setFirstResult(0);
6255                    q.setMaxResults(2);
6256    
6257                    if (getDB().isSupportsInlineDistinct()) {
6258                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6259                    }
6260                    else {
6261                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6262                    }
6263    
6264                    QueryPos qPos = QueryPos.getInstance(q);
6265    
6266                    qPos.add(groupId);
6267    
6268                    qPos.add(status);
6269    
6270                    if (orderByComparator != null) {
6271                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6272    
6273                            for (Object value : values) {
6274                                    qPos.add(value);
6275                            }
6276                    }
6277    
6278                    List<MBMessage> list = q.list();
6279    
6280                    if (list.size() == 2) {
6281                            return list.get(1);
6282                    }
6283                    else {
6284                            return null;
6285                    }
6286            }
6287    
6288            /**
6289             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
6290             *
6291             * @param companyId the company ID
6292             * @param status the status
6293             * @return the matching message-boards messages
6294             * @throws SystemException if a system exception occurred
6295             */
6296            public List<MBMessage> findByC_S(long companyId, int status)
6297                    throws SystemException {
6298                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
6299                            QueryUtil.ALL_POS, null);
6300            }
6301    
6302            /**
6303             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
6304             *
6305             * <p>
6306             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6307             * </p>
6308             *
6309             * @param companyId the company ID
6310             * @param status the status
6311             * @param start the lower bound of the range of message-boards messages
6312             * @param end the upper bound of the range of message-boards messages (not inclusive)
6313             * @return the range of matching message-boards messages
6314             * @throws SystemException if a system exception occurred
6315             */
6316            public List<MBMessage> findByC_S(long companyId, int status, int start,
6317                    int end) throws SystemException {
6318                    return findByC_S(companyId, status, start, end, null);
6319            }
6320    
6321            /**
6322             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
6323             *
6324             * <p>
6325             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6326             * </p>
6327             *
6328             * @param companyId the company ID
6329             * @param status the status
6330             * @param start the lower bound of the range of message-boards messages
6331             * @param end the upper bound of the range of message-boards messages (not inclusive)
6332             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6333             * @return the ordered range of matching message-boards messages
6334             * @throws SystemException if a system exception occurred
6335             */
6336            public List<MBMessage> findByC_S(long companyId, int status, int start,
6337                    int end, OrderByComparator orderByComparator) throws SystemException {
6338                    FinderPath finderPath = null;
6339                    Object[] finderArgs = null;
6340    
6341                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6342                                    (orderByComparator == null)) {
6343                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
6344                            finderArgs = new Object[] { companyId, status };
6345                    }
6346                    else {
6347                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
6348                            finderArgs = new Object[] {
6349                                            companyId, status,
6350                                            
6351                                            start, end, orderByComparator
6352                                    };
6353                    }
6354    
6355                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6356                                    finderArgs, this);
6357    
6358                    if (list == null) {
6359                            StringBundler query = null;
6360    
6361                            if (orderByComparator != null) {
6362                                    query = new StringBundler(4 +
6363                                                    (orderByComparator.getOrderByFields().length * 3));
6364                            }
6365                            else {
6366                                    query = new StringBundler(4);
6367                            }
6368    
6369                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6370    
6371                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
6372    
6373                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
6374    
6375                            if (orderByComparator != null) {
6376                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6377                                            orderByComparator);
6378                            }
6379    
6380                            else {
6381                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6382                            }
6383    
6384                            String sql = query.toString();
6385    
6386                            Session session = null;
6387    
6388                            try {
6389                                    session = openSession();
6390    
6391                                    Query q = session.createQuery(sql);
6392    
6393                                    QueryPos qPos = QueryPos.getInstance(q);
6394    
6395                                    qPos.add(companyId);
6396    
6397                                    qPos.add(status);
6398    
6399                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
6400                                                    end);
6401                            }
6402                            catch (Exception e) {
6403                                    throw processException(e);
6404                            }
6405                            finally {
6406                                    if (list == null) {
6407                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
6408                                    }
6409                                    else {
6410                                            cacheResult(list);
6411    
6412                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
6413                                    }
6414    
6415                                    closeSession(session);
6416                            }
6417                    }
6418    
6419                    return list;
6420            }
6421    
6422            /**
6423             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
6424             *
6425             * <p>
6426             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6427             * </p>
6428             *
6429             * @param companyId the company ID
6430             * @param status the status
6431             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6432             * @return the first matching message-boards message
6433             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6434             * @throws SystemException if a system exception occurred
6435             */
6436            public MBMessage findByC_S_First(long companyId, int status,
6437                    OrderByComparator orderByComparator)
6438                    throws NoSuchMessageException, SystemException {
6439                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
6440                                    orderByComparator);
6441    
6442                    if (list.isEmpty()) {
6443                            StringBundler msg = new StringBundler(6);
6444    
6445                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6446    
6447                            msg.append("companyId=");
6448                            msg.append(companyId);
6449    
6450                            msg.append(", status=");
6451                            msg.append(status);
6452    
6453                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6454    
6455                            throw new NoSuchMessageException(msg.toString());
6456                    }
6457                    else {
6458                            return list.get(0);
6459                    }
6460            }
6461    
6462            /**
6463             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
6464             *
6465             * <p>
6466             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6467             * </p>
6468             *
6469             * @param companyId the company ID
6470             * @param status the status
6471             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6472             * @return the last matching message-boards message
6473             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6474             * @throws SystemException if a system exception occurred
6475             */
6476            public MBMessage findByC_S_Last(long companyId, int status,
6477                    OrderByComparator orderByComparator)
6478                    throws NoSuchMessageException, SystemException {
6479                    int count = countByC_S(companyId, status);
6480    
6481                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
6482                                    orderByComparator);
6483    
6484                    if (list.isEmpty()) {
6485                            StringBundler msg = new StringBundler(6);
6486    
6487                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6488    
6489                            msg.append("companyId=");
6490                            msg.append(companyId);
6491    
6492                            msg.append(", status=");
6493                            msg.append(status);
6494    
6495                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6496    
6497                            throw new NoSuchMessageException(msg.toString());
6498                    }
6499                    else {
6500                            return list.get(0);
6501                    }
6502            }
6503    
6504            /**
6505             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
6506             *
6507             * <p>
6508             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6509             * </p>
6510             *
6511             * @param messageId the primary key of the current message-boards message
6512             * @param companyId the company ID
6513             * @param status the status
6514             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6515             * @return the previous, current, and next message-boards message
6516             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6517             * @throws SystemException if a system exception occurred
6518             */
6519            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
6520                    int status, OrderByComparator orderByComparator)
6521                    throws NoSuchMessageException, SystemException {
6522                    MBMessage mbMessage = findByPrimaryKey(messageId);
6523    
6524                    Session session = null;
6525    
6526                    try {
6527                            session = openSession();
6528    
6529                            MBMessage[] array = new MBMessageImpl[3];
6530    
6531                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
6532                                            status, orderByComparator, true);
6533    
6534                            array[1] = mbMessage;
6535    
6536                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
6537                                            status, orderByComparator, false);
6538    
6539                            return array;
6540                    }
6541                    catch (Exception e) {
6542                            throw processException(e);
6543                    }
6544                    finally {
6545                            closeSession(session);
6546                    }
6547            }
6548    
6549            protected MBMessage getByC_S_PrevAndNext(Session session,
6550                    MBMessage mbMessage, long companyId, int status,
6551                    OrderByComparator orderByComparator, boolean previous) {
6552                    StringBundler query = null;
6553    
6554                    if (orderByComparator != null) {
6555                            query = new StringBundler(6 +
6556                                            (orderByComparator.getOrderByFields().length * 6));
6557                    }
6558                    else {
6559                            query = new StringBundler(3);
6560                    }
6561    
6562                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6563    
6564                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
6565    
6566                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
6567    
6568                    if (orderByComparator != null) {
6569                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6570    
6571                            if (orderByConditionFields.length > 0) {
6572                                    query.append(WHERE_AND);
6573                            }
6574    
6575                            for (int i = 0; i < orderByConditionFields.length; i++) {
6576                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6577                                    query.append(orderByConditionFields[i]);
6578    
6579                                    if ((i + 1) < orderByConditionFields.length) {
6580                                            if (orderByComparator.isAscending() ^ previous) {
6581                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6582                                            }
6583                                            else {
6584                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6585                                            }
6586                                    }
6587                                    else {
6588                                            if (orderByComparator.isAscending() ^ previous) {
6589                                                    query.append(WHERE_GREATER_THAN);
6590                                            }
6591                                            else {
6592                                                    query.append(WHERE_LESSER_THAN);
6593                                            }
6594                                    }
6595                            }
6596    
6597                            query.append(ORDER_BY_CLAUSE);
6598    
6599                            String[] orderByFields = orderByComparator.getOrderByFields();
6600    
6601                            for (int i = 0; i < orderByFields.length; i++) {
6602                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6603                                    query.append(orderByFields[i]);
6604    
6605                                    if ((i + 1) < orderByFields.length) {
6606                                            if (orderByComparator.isAscending() ^ previous) {
6607                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6608                                            }
6609                                            else {
6610                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6611                                            }
6612                                    }
6613                                    else {
6614                                            if (orderByComparator.isAscending() ^ previous) {
6615                                                    query.append(ORDER_BY_ASC);
6616                                            }
6617                                            else {
6618                                                    query.append(ORDER_BY_DESC);
6619                                            }
6620                                    }
6621                            }
6622                    }
6623    
6624                    else {
6625                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6626                    }
6627    
6628                    String sql = query.toString();
6629    
6630                    Query q = session.createQuery(sql);
6631    
6632                    q.setFirstResult(0);
6633                    q.setMaxResults(2);
6634    
6635                    QueryPos qPos = QueryPos.getInstance(q);
6636    
6637                    qPos.add(companyId);
6638    
6639                    qPos.add(status);
6640    
6641                    if (orderByComparator != null) {
6642                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6643    
6644                            for (Object value : values) {
6645                                    qPos.add(value);
6646                            }
6647                    }
6648    
6649                    List<MBMessage> list = q.list();
6650    
6651                    if (list.size() == 2) {
6652                            return list.get(1);
6653                    }
6654                    else {
6655                            return null;
6656                    }
6657            }
6658    
6659            /**
6660             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
6661             *
6662             * @param userId the user ID
6663             * @param classNameId the class name ID
6664             * @return the matching message-boards messages
6665             * @throws SystemException if a system exception occurred
6666             */
6667            public List<MBMessage> findByU_C(long userId, long classNameId)
6668                    throws SystemException {
6669                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
6670                            QueryUtil.ALL_POS, null);
6671            }
6672    
6673            /**
6674             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
6675             *
6676             * <p>
6677             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6678             * </p>
6679             *
6680             * @param userId the user ID
6681             * @param classNameId the class name ID
6682             * @param start the lower bound of the range of message-boards messages
6683             * @param end the upper bound of the range of message-boards messages (not inclusive)
6684             * @return the range of matching message-boards messages
6685             * @throws SystemException if a system exception occurred
6686             */
6687            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
6688                    int end) throws SystemException {
6689                    return findByU_C(userId, classNameId, start, end, null);
6690            }
6691    
6692            /**
6693             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
6694             *
6695             * <p>
6696             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6697             * </p>
6698             *
6699             * @param userId the user ID
6700             * @param classNameId the class name ID
6701             * @param start the lower bound of the range of message-boards messages
6702             * @param end the upper bound of the range of message-boards messages (not inclusive)
6703             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6704             * @return the ordered range of matching message-boards messages
6705             * @throws SystemException if a system exception occurred
6706             */
6707            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
6708                    int end, OrderByComparator orderByComparator) throws SystemException {
6709                    FinderPath finderPath = null;
6710                    Object[] finderArgs = null;
6711    
6712                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6713                                    (orderByComparator == null)) {
6714                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
6715                            finderArgs = new Object[] { userId, classNameId };
6716                    }
6717                    else {
6718                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
6719                            finderArgs = new Object[] {
6720                                            userId, classNameId,
6721                                            
6722                                            start, end, orderByComparator
6723                                    };
6724                    }
6725    
6726                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6727                                    finderArgs, this);
6728    
6729                    if (list == null) {
6730                            StringBundler query = null;
6731    
6732                            if (orderByComparator != null) {
6733                                    query = new StringBundler(4 +
6734                                                    (orderByComparator.getOrderByFields().length * 3));
6735                            }
6736                            else {
6737                                    query = new StringBundler(4);
6738                            }
6739    
6740                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6741    
6742                            query.append(_FINDER_COLUMN_U_C_USERID_2);
6743    
6744                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
6745    
6746                            if (orderByComparator != null) {
6747                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6748                                            orderByComparator);
6749                            }
6750    
6751                            else {
6752                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6753                            }
6754    
6755                            String sql = query.toString();
6756    
6757                            Session session = null;
6758    
6759                            try {
6760                                    session = openSession();
6761    
6762                                    Query q = session.createQuery(sql);
6763    
6764                                    QueryPos qPos = QueryPos.getInstance(q);
6765    
6766                                    qPos.add(userId);
6767    
6768                                    qPos.add(classNameId);
6769    
6770                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
6771                                                    end);
6772                            }
6773                            catch (Exception e) {
6774                                    throw processException(e);
6775                            }
6776                            finally {
6777                                    if (list == null) {
6778                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
6779                                    }
6780                                    else {
6781                                            cacheResult(list);
6782    
6783                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
6784                                    }
6785    
6786                                    closeSession(session);
6787                            }
6788                    }
6789    
6790                    return list;
6791            }
6792    
6793            /**
6794             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
6795             *
6796             * <p>
6797             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6798             * </p>
6799             *
6800             * @param userId the user ID
6801             * @param classNameId the class name ID
6802             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6803             * @return the first matching message-boards message
6804             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6805             * @throws SystemException if a system exception occurred
6806             */
6807            public MBMessage findByU_C_First(long userId, long classNameId,
6808                    OrderByComparator orderByComparator)
6809                    throws NoSuchMessageException, SystemException {
6810                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
6811                                    orderByComparator);
6812    
6813                    if (list.isEmpty()) {
6814                            StringBundler msg = new StringBundler(6);
6815    
6816                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6817    
6818                            msg.append("userId=");
6819                            msg.append(userId);
6820    
6821                            msg.append(", classNameId=");
6822                            msg.append(classNameId);
6823    
6824                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6825    
6826                            throw new NoSuchMessageException(msg.toString());
6827                    }
6828                    else {
6829                            return list.get(0);
6830                    }
6831            }
6832    
6833            /**
6834             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
6835             *
6836             * <p>
6837             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6838             * </p>
6839             *
6840             * @param userId the user ID
6841             * @param classNameId the class name ID
6842             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6843             * @return the last matching message-boards message
6844             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6845             * @throws SystemException if a system exception occurred
6846             */
6847            public MBMessage findByU_C_Last(long userId, long classNameId,
6848                    OrderByComparator orderByComparator)
6849                    throws NoSuchMessageException, SystemException {
6850                    int count = countByU_C(userId, classNameId);
6851    
6852                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
6853                                    orderByComparator);
6854    
6855                    if (list.isEmpty()) {
6856                            StringBundler msg = new StringBundler(6);
6857    
6858                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6859    
6860                            msg.append("userId=");
6861                            msg.append(userId);
6862    
6863                            msg.append(", classNameId=");
6864                            msg.append(classNameId);
6865    
6866                            msg.append(StringPool.CLOSE_CURLY_BRACE);
6867    
6868                            throw new NoSuchMessageException(msg.toString());
6869                    }
6870                    else {
6871                            return list.get(0);
6872                    }
6873            }
6874    
6875            /**
6876             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
6877             *
6878             * <p>
6879             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6880             * </p>
6881             *
6882             * @param messageId the primary key of the current message-boards message
6883             * @param userId the user ID
6884             * @param classNameId the class name ID
6885             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6886             * @return the previous, current, and next message-boards message
6887             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6888             * @throws SystemException if a system exception occurred
6889             */
6890            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
6891                    long classNameId, OrderByComparator orderByComparator)
6892                    throws NoSuchMessageException, SystemException {
6893                    MBMessage mbMessage = findByPrimaryKey(messageId);
6894    
6895                    Session session = null;
6896    
6897                    try {
6898                            session = openSession();
6899    
6900                            MBMessage[] array = new MBMessageImpl[3];
6901    
6902                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
6903                                            classNameId, orderByComparator, true);
6904    
6905                            array[1] = mbMessage;
6906    
6907                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
6908                                            classNameId, orderByComparator, false);
6909    
6910                            return array;
6911                    }
6912                    catch (Exception e) {
6913                            throw processException(e);
6914                    }
6915                    finally {
6916                            closeSession(session);
6917                    }
6918            }
6919    
6920            protected MBMessage getByU_C_PrevAndNext(Session session,
6921                    MBMessage mbMessage, long userId, long classNameId,
6922                    OrderByComparator orderByComparator, boolean previous) {
6923                    StringBundler query = null;
6924    
6925                    if (orderByComparator != null) {
6926                            query = new StringBundler(6 +
6927                                            (orderByComparator.getOrderByFields().length * 6));
6928                    }
6929                    else {
6930                            query = new StringBundler(3);
6931                    }
6932    
6933                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6934    
6935                    query.append(_FINDER_COLUMN_U_C_USERID_2);
6936    
6937                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
6938    
6939                    if (orderByComparator != null) {
6940                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6941    
6942                            if (orderByConditionFields.length > 0) {
6943                                    query.append(WHERE_AND);
6944                            }
6945    
6946                            for (int i = 0; i < orderByConditionFields.length; i++) {
6947                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6948                                    query.append(orderByConditionFields[i]);
6949    
6950                                    if ((i + 1) < orderByConditionFields.length) {
6951                                            if (orderByComparator.isAscending() ^ previous) {
6952                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6953                                            }
6954                                            else {
6955                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6956                                            }
6957                                    }
6958                                    else {
6959                                            if (orderByComparator.isAscending() ^ previous) {
6960                                                    query.append(WHERE_GREATER_THAN);
6961                                            }
6962                                            else {
6963                                                    query.append(WHERE_LESSER_THAN);
6964                                            }
6965                                    }
6966                            }
6967    
6968                            query.append(ORDER_BY_CLAUSE);
6969    
6970                            String[] orderByFields = orderByComparator.getOrderByFields();
6971    
6972                            for (int i = 0; i < orderByFields.length; i++) {
6973                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6974                                    query.append(orderByFields[i]);
6975    
6976                                    if ((i + 1) < orderByFields.length) {
6977                                            if (orderByComparator.isAscending() ^ previous) {
6978                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6979                                            }
6980                                            else {
6981                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6982                                            }
6983                                    }
6984                                    else {
6985                                            if (orderByComparator.isAscending() ^ previous) {
6986                                                    query.append(ORDER_BY_ASC);
6987                                            }
6988                                            else {
6989                                                    query.append(ORDER_BY_DESC);
6990                                            }
6991                                    }
6992                            }
6993                    }
6994    
6995                    else {
6996                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6997                    }
6998    
6999                    String sql = query.toString();
7000    
7001                    Query q = session.createQuery(sql);
7002    
7003                    q.setFirstResult(0);
7004                    q.setMaxResults(2);
7005    
7006                    QueryPos qPos = QueryPos.getInstance(q);
7007    
7008                    qPos.add(userId);
7009    
7010                    qPos.add(classNameId);
7011    
7012                    if (orderByComparator != null) {
7013                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7014    
7015                            for (Object value : values) {
7016                                    qPos.add(value);
7017                            }
7018                    }
7019    
7020                    List<MBMessage> list = q.list();
7021    
7022                    if (list.size() == 2) {
7023                            return list.get(1);
7024                    }
7025                    else {
7026                            return null;
7027                    }
7028            }
7029    
7030            /**
7031             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7032             *
7033             * <p>
7034             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7035             * </p>
7036             *
7037             * @param userId the user ID
7038             * @param classNameIds the class name IDs
7039             * @return the matching message-boards messages
7040             * @throws SystemException if a system exception occurred
7041             */
7042            public List<MBMessage> findByU_C(long userId, long[] classNameIds)
7043                    throws SystemException {
7044                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
7045                            QueryUtil.ALL_POS, null);
7046            }
7047    
7048            /**
7049             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7050             *
7051             * <p>
7052             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7053             * </p>
7054             *
7055             * @param userId the user ID
7056             * @param classNameIds the class name IDs
7057             * @param start the lower bound of the range of message-boards messages
7058             * @param end the upper bound of the range of message-boards messages (not inclusive)
7059             * @return the range of matching message-boards messages
7060             * @throws SystemException if a system exception occurred
7061             */
7062            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7063                    int start, int end) throws SystemException {
7064                    return findByU_C(userId, classNameIds, start, end, null);
7065            }
7066    
7067            /**
7068             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7069             *
7070             * <p>
7071             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7072             * </p>
7073             *
7074             * @param userId the user ID
7075             * @param classNameIds the class name IDs
7076             * @param start the lower bound of the range of message-boards messages
7077             * @param end the upper bound of the range of message-boards messages (not inclusive)
7078             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7079             * @return the ordered range of matching message-boards messages
7080             * @throws SystemException if a system exception occurred
7081             */
7082            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7083                    int start, int end, OrderByComparator orderByComparator)
7084                    throws SystemException {
7085                    FinderPath finderPath = null;
7086                    Object[] finderArgs = null;
7087    
7088                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7089                                    (orderByComparator == null)) {
7090                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7091                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
7092                    }
7093                    else {
7094                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7095                            finderArgs = new Object[] {
7096                                            userId, StringUtil.merge(classNameIds),
7097                                            
7098                                            start, end, orderByComparator
7099                                    };
7100                    }
7101    
7102                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7103                                    finderArgs, this);
7104    
7105                    if (list == null) {
7106                            StringBundler query = new StringBundler();
7107    
7108                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7109    
7110                            boolean conjunctionable = false;
7111    
7112                            if (conjunctionable) {
7113                                    query.append(WHERE_AND);
7114                            }
7115    
7116                            query.append(_FINDER_COLUMN_U_C_USERID_5);
7117    
7118                            conjunctionable = true;
7119    
7120                            if ((classNameIds == null) || (classNameIds.length > 0)) {
7121                                    if (conjunctionable) {
7122                                            query.append(WHERE_AND);
7123                                    }
7124    
7125                                    query.append(StringPool.OPEN_PARENTHESIS);
7126    
7127                                    for (int i = 0; i < classNameIds.length; i++) {
7128                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
7129    
7130                                            if ((i + 1) < classNameIds.length) {
7131                                                    query.append(WHERE_OR);
7132                                            }
7133                                    }
7134    
7135                                    query.append(StringPool.CLOSE_PARENTHESIS);
7136    
7137                                    conjunctionable = true;
7138                            }
7139    
7140                            if (orderByComparator != null) {
7141                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7142                                            orderByComparator);
7143                            }
7144    
7145                            else {
7146                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7147                            }
7148    
7149                            String sql = query.toString();
7150    
7151                            Session session = null;
7152    
7153                            try {
7154                                    session = openSession();
7155    
7156                                    Query q = session.createQuery(sql);
7157    
7158                                    QueryPos qPos = QueryPos.getInstance(q);
7159    
7160                                    qPos.add(userId);
7161    
7162                                    if (classNameIds != null) {
7163                                            qPos.add(classNameIds);
7164                                    }
7165    
7166                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7167                                                    end);
7168                            }
7169                            catch (Exception e) {
7170                                    throw processException(e);
7171                            }
7172                            finally {
7173                                    if (list == null) {
7174                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
7175                                    }
7176                                    else {
7177                                            cacheResult(list);
7178    
7179                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
7180                                    }
7181    
7182                                    closeSession(session);
7183                            }
7184                    }
7185    
7186                    return list;
7187            }
7188    
7189            /**
7190             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
7191             *
7192             * @param classNameId the class name ID
7193             * @param classPK the class p k
7194             * @return the matching message-boards messages
7195             * @throws SystemException if a system exception occurred
7196             */
7197            public List<MBMessage> findByC_C(long classNameId, long classPK)
7198                    throws SystemException {
7199                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
7200                            QueryUtil.ALL_POS, null);
7201            }
7202    
7203            /**
7204             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
7205             *
7206             * <p>
7207             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7208             * </p>
7209             *
7210             * @param classNameId the class name ID
7211             * @param classPK the class p k
7212             * @param start the lower bound of the range of message-boards messages
7213             * @param end the upper bound of the range of message-boards messages (not inclusive)
7214             * @return the range of matching message-boards messages
7215             * @throws SystemException if a system exception occurred
7216             */
7217            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
7218                    int end) throws SystemException {
7219                    return findByC_C(classNameId, classPK, start, end, null);
7220            }
7221    
7222            /**
7223             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
7224             *
7225             * <p>
7226             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7227             * </p>
7228             *
7229             * @param classNameId the class name ID
7230             * @param classPK the class p k
7231             * @param start the lower bound of the range of message-boards messages
7232             * @param end the upper bound of the range of message-boards messages (not inclusive)
7233             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7234             * @return the ordered range of matching message-boards messages
7235             * @throws SystemException if a system exception occurred
7236             */
7237            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
7238                    int end, OrderByComparator orderByComparator) throws SystemException {
7239                    FinderPath finderPath = null;
7240                    Object[] finderArgs = null;
7241    
7242                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7243                                    (orderByComparator == null)) {
7244                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
7245                            finderArgs = new Object[] { classNameId, classPK };
7246                    }
7247                    else {
7248                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
7249                            finderArgs = new Object[] {
7250                                            classNameId, classPK,
7251                                            
7252                                            start, end, orderByComparator
7253                                    };
7254                    }
7255    
7256                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7257                                    finderArgs, this);
7258    
7259                    if (list == null) {
7260                            StringBundler query = null;
7261    
7262                            if (orderByComparator != null) {
7263                                    query = new StringBundler(4 +
7264                                                    (orderByComparator.getOrderByFields().length * 3));
7265                            }
7266                            else {
7267                                    query = new StringBundler(4);
7268                            }
7269    
7270                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7271    
7272                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
7273    
7274                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
7275    
7276                            if (orderByComparator != null) {
7277                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7278                                            orderByComparator);
7279                            }
7280    
7281                            else {
7282                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7283                            }
7284    
7285                            String sql = query.toString();
7286    
7287                            Session session = null;
7288    
7289                            try {
7290                                    session = openSession();
7291    
7292                                    Query q = session.createQuery(sql);
7293    
7294                                    QueryPos qPos = QueryPos.getInstance(q);
7295    
7296                                    qPos.add(classNameId);
7297    
7298                                    qPos.add(classPK);
7299    
7300                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7301                                                    end);
7302                            }
7303                            catch (Exception e) {
7304                                    throw processException(e);
7305                            }
7306                            finally {
7307                                    if (list == null) {
7308                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
7309                                    }
7310                                    else {
7311                                            cacheResult(list);
7312    
7313                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
7314                                    }
7315    
7316                                    closeSession(session);
7317                            }
7318                    }
7319    
7320                    return list;
7321            }
7322    
7323            /**
7324             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
7325             *
7326             * <p>
7327             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7328             * </p>
7329             *
7330             * @param classNameId the class name ID
7331             * @param classPK the class p k
7332             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7333             * @return the first matching message-boards message
7334             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7335             * @throws SystemException if a system exception occurred
7336             */
7337            public MBMessage findByC_C_First(long classNameId, long classPK,
7338                    OrderByComparator orderByComparator)
7339                    throws NoSuchMessageException, SystemException {
7340                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
7341                                    orderByComparator);
7342    
7343                    if (list.isEmpty()) {
7344                            StringBundler msg = new StringBundler(6);
7345    
7346                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7347    
7348                            msg.append("classNameId=");
7349                            msg.append(classNameId);
7350    
7351                            msg.append(", classPK=");
7352                            msg.append(classPK);
7353    
7354                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7355    
7356                            throw new NoSuchMessageException(msg.toString());
7357                    }
7358                    else {
7359                            return list.get(0);
7360                    }
7361            }
7362    
7363            /**
7364             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
7365             *
7366             * <p>
7367             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7368             * </p>
7369             *
7370             * @param classNameId the class name ID
7371             * @param classPK the class p k
7372             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7373             * @return the last matching message-boards message
7374             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7375             * @throws SystemException if a system exception occurred
7376             */
7377            public MBMessage findByC_C_Last(long classNameId, long classPK,
7378                    OrderByComparator orderByComparator)
7379                    throws NoSuchMessageException, SystemException {
7380                    int count = countByC_C(classNameId, classPK);
7381    
7382                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
7383                                    count, orderByComparator);
7384    
7385                    if (list.isEmpty()) {
7386                            StringBundler msg = new StringBundler(6);
7387    
7388                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7389    
7390                            msg.append("classNameId=");
7391                            msg.append(classNameId);
7392    
7393                            msg.append(", classPK=");
7394                            msg.append(classPK);
7395    
7396                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7397    
7398                            throw new NoSuchMessageException(msg.toString());
7399                    }
7400                    else {
7401                            return list.get(0);
7402                    }
7403            }
7404    
7405            /**
7406             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
7407             *
7408             * <p>
7409             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7410             * </p>
7411             *
7412             * @param messageId the primary key of the current message-boards message
7413             * @param classNameId the class name ID
7414             * @param classPK the class p k
7415             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7416             * @return the previous, current, and next message-boards message
7417             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7418             * @throws SystemException if a system exception occurred
7419             */
7420            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
7421                    long classPK, OrderByComparator orderByComparator)
7422                    throws NoSuchMessageException, SystemException {
7423                    MBMessage mbMessage = findByPrimaryKey(messageId);
7424    
7425                    Session session = null;
7426    
7427                    try {
7428                            session = openSession();
7429    
7430                            MBMessage[] array = new MBMessageImpl[3];
7431    
7432                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
7433                                            classPK, orderByComparator, true);
7434    
7435                            array[1] = mbMessage;
7436    
7437                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
7438                                            classPK, orderByComparator, false);
7439    
7440                            return array;
7441                    }
7442                    catch (Exception e) {
7443                            throw processException(e);
7444                    }
7445                    finally {
7446                            closeSession(session);
7447                    }
7448            }
7449    
7450            protected MBMessage getByC_C_PrevAndNext(Session session,
7451                    MBMessage mbMessage, long classNameId, long classPK,
7452                    OrderByComparator orderByComparator, boolean previous) {
7453                    StringBundler query = null;
7454    
7455                    if (orderByComparator != null) {
7456                            query = new StringBundler(6 +
7457                                            (orderByComparator.getOrderByFields().length * 6));
7458                    }
7459                    else {
7460                            query = new StringBundler(3);
7461                    }
7462    
7463                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7464    
7465                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
7466    
7467                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
7468    
7469                    if (orderByComparator != null) {
7470                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7471    
7472                            if (orderByConditionFields.length > 0) {
7473                                    query.append(WHERE_AND);
7474                            }
7475    
7476                            for (int i = 0; i < orderByConditionFields.length; i++) {
7477                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7478                                    query.append(orderByConditionFields[i]);
7479    
7480                                    if ((i + 1) < orderByConditionFields.length) {
7481                                            if (orderByComparator.isAscending() ^ previous) {
7482                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7483                                            }
7484                                            else {
7485                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7486                                            }
7487                                    }
7488                                    else {
7489                                            if (orderByComparator.isAscending() ^ previous) {
7490                                                    query.append(WHERE_GREATER_THAN);
7491                                            }
7492                                            else {
7493                                                    query.append(WHERE_LESSER_THAN);
7494                                            }
7495                                    }
7496                            }
7497    
7498                            query.append(ORDER_BY_CLAUSE);
7499    
7500                            String[] orderByFields = orderByComparator.getOrderByFields();
7501    
7502                            for (int i = 0; i < orderByFields.length; i++) {
7503                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7504                                    query.append(orderByFields[i]);
7505    
7506                                    if ((i + 1) < orderByFields.length) {
7507                                            if (orderByComparator.isAscending() ^ previous) {
7508                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7509                                            }
7510                                            else {
7511                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7512                                            }
7513                                    }
7514                                    else {
7515                                            if (orderByComparator.isAscending() ^ previous) {
7516                                                    query.append(ORDER_BY_ASC);
7517                                            }
7518                                            else {
7519                                                    query.append(ORDER_BY_DESC);
7520                                            }
7521                                    }
7522                            }
7523                    }
7524    
7525                    else {
7526                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7527                    }
7528    
7529                    String sql = query.toString();
7530    
7531                    Query q = session.createQuery(sql);
7532    
7533                    q.setFirstResult(0);
7534                    q.setMaxResults(2);
7535    
7536                    QueryPos qPos = QueryPos.getInstance(q);
7537    
7538                    qPos.add(classNameId);
7539    
7540                    qPos.add(classPK);
7541    
7542                    if (orderByComparator != null) {
7543                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7544    
7545                            for (Object value : values) {
7546                                    qPos.add(value);
7547                            }
7548                    }
7549    
7550                    List<MBMessage> list = q.list();
7551    
7552                    if (list.size() == 2) {
7553                            return list.get(1);
7554                    }
7555                    else {
7556                            return null;
7557                    }
7558            }
7559    
7560            /**
7561             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
7562             *
7563             * @param threadId the thread ID
7564             * @param parentMessageId the parent message ID
7565             * @return the matching message-boards messages
7566             * @throws SystemException if a system exception occurred
7567             */
7568            public List<MBMessage> findByT_P(long threadId, long parentMessageId)
7569                    throws SystemException {
7570                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
7571                            QueryUtil.ALL_POS, null);
7572            }
7573    
7574            /**
7575             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
7576             *
7577             * <p>
7578             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7579             * </p>
7580             *
7581             * @param threadId the thread ID
7582             * @param parentMessageId the parent message ID
7583             * @param start the lower bound of the range of message-boards messages
7584             * @param end the upper bound of the range of message-boards messages (not inclusive)
7585             * @return the range of matching message-boards messages
7586             * @throws SystemException if a system exception occurred
7587             */
7588            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
7589                    int start, int end) throws SystemException {
7590                    return findByT_P(threadId, parentMessageId, start, end, null);
7591            }
7592    
7593            /**
7594             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
7595             *
7596             * <p>
7597             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7598             * </p>
7599             *
7600             * @param threadId the thread ID
7601             * @param parentMessageId the parent message ID
7602             * @param start the lower bound of the range of message-boards messages
7603             * @param end the upper bound of the range of message-boards messages (not inclusive)
7604             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7605             * @return the ordered range of matching message-boards messages
7606             * @throws SystemException if a system exception occurred
7607             */
7608            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
7609                    int start, int end, OrderByComparator orderByComparator)
7610                    throws SystemException {
7611                    FinderPath finderPath = null;
7612                    Object[] finderArgs = null;
7613    
7614                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7615                                    (orderByComparator == null)) {
7616                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
7617                            finderArgs = new Object[] { threadId, parentMessageId };
7618                    }
7619                    else {
7620                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
7621                            finderArgs = new Object[] {
7622                                            threadId, parentMessageId,
7623                                            
7624                                            start, end, orderByComparator
7625                                    };
7626                    }
7627    
7628                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7629                                    finderArgs, this);
7630    
7631                    if (list == null) {
7632                            StringBundler query = null;
7633    
7634                            if (orderByComparator != null) {
7635                                    query = new StringBundler(4 +
7636                                                    (orderByComparator.getOrderByFields().length * 3));
7637                            }
7638                            else {
7639                                    query = new StringBundler(4);
7640                            }
7641    
7642                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7643    
7644                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
7645    
7646                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
7647    
7648                            if (orderByComparator != null) {
7649                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7650                                            orderByComparator);
7651                            }
7652    
7653                            else {
7654                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7655                            }
7656    
7657                            String sql = query.toString();
7658    
7659                            Session session = null;
7660    
7661                            try {
7662                                    session = openSession();
7663    
7664                                    Query q = session.createQuery(sql);
7665    
7666                                    QueryPos qPos = QueryPos.getInstance(q);
7667    
7668                                    qPos.add(threadId);
7669    
7670                                    qPos.add(parentMessageId);
7671    
7672                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7673                                                    end);
7674                            }
7675                            catch (Exception e) {
7676                                    throw processException(e);
7677                            }
7678                            finally {
7679                                    if (list == null) {
7680                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
7681                                    }
7682                                    else {
7683                                            cacheResult(list);
7684    
7685                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
7686                                    }
7687    
7688                                    closeSession(session);
7689                            }
7690                    }
7691    
7692                    return list;
7693            }
7694    
7695            /**
7696             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
7697             *
7698             * <p>
7699             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7700             * </p>
7701             *
7702             * @param threadId the thread ID
7703             * @param parentMessageId the parent message ID
7704             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7705             * @return the first matching message-boards message
7706             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7707             * @throws SystemException if a system exception occurred
7708             */
7709            public MBMessage findByT_P_First(long threadId, long parentMessageId,
7710                    OrderByComparator orderByComparator)
7711                    throws NoSuchMessageException, SystemException {
7712                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
7713                                    orderByComparator);
7714    
7715                    if (list.isEmpty()) {
7716                            StringBundler msg = new StringBundler(6);
7717    
7718                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7719    
7720                            msg.append("threadId=");
7721                            msg.append(threadId);
7722    
7723                            msg.append(", parentMessageId=");
7724                            msg.append(parentMessageId);
7725    
7726                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7727    
7728                            throw new NoSuchMessageException(msg.toString());
7729                    }
7730                    else {
7731                            return list.get(0);
7732                    }
7733            }
7734    
7735            /**
7736             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
7737             *
7738             * <p>
7739             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7740             * </p>
7741             *
7742             * @param threadId the thread ID
7743             * @param parentMessageId the parent message ID
7744             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7745             * @return the last matching message-boards message
7746             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7747             * @throws SystemException if a system exception occurred
7748             */
7749            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
7750                    OrderByComparator orderByComparator)
7751                    throws NoSuchMessageException, SystemException {
7752                    int count = countByT_P(threadId, parentMessageId);
7753    
7754                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
7755                                    count, orderByComparator);
7756    
7757                    if (list.isEmpty()) {
7758                            StringBundler msg = new StringBundler(6);
7759    
7760                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7761    
7762                            msg.append("threadId=");
7763                            msg.append(threadId);
7764    
7765                            msg.append(", parentMessageId=");
7766                            msg.append(parentMessageId);
7767    
7768                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7769    
7770                            throw new NoSuchMessageException(msg.toString());
7771                    }
7772                    else {
7773                            return list.get(0);
7774                    }
7775            }
7776    
7777            /**
7778             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
7779             *
7780             * <p>
7781             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7782             * </p>
7783             *
7784             * @param messageId the primary key of the current message-boards message
7785             * @param threadId the thread ID
7786             * @param parentMessageId the parent message ID
7787             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7788             * @return the previous, current, and next message-boards message
7789             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7790             * @throws SystemException if a system exception occurred
7791             */
7792            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
7793                    long parentMessageId, OrderByComparator orderByComparator)
7794                    throws NoSuchMessageException, SystemException {
7795                    MBMessage mbMessage = findByPrimaryKey(messageId);
7796    
7797                    Session session = null;
7798    
7799                    try {
7800                            session = openSession();
7801    
7802                            MBMessage[] array = new MBMessageImpl[3];
7803    
7804                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
7805                                            parentMessageId, orderByComparator, true);
7806    
7807                            array[1] = mbMessage;
7808    
7809                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
7810                                            parentMessageId, orderByComparator, false);
7811    
7812                            return array;
7813                    }
7814                    catch (Exception e) {
7815                            throw processException(e);
7816                    }
7817                    finally {
7818                            closeSession(session);
7819                    }
7820            }
7821    
7822            protected MBMessage getByT_P_PrevAndNext(Session session,
7823                    MBMessage mbMessage, long threadId, long parentMessageId,
7824                    OrderByComparator orderByComparator, boolean previous) {
7825                    StringBundler query = null;
7826    
7827                    if (orderByComparator != null) {
7828                            query = new StringBundler(6 +
7829                                            (orderByComparator.getOrderByFields().length * 6));
7830                    }
7831                    else {
7832                            query = new StringBundler(3);
7833                    }
7834    
7835                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7836    
7837                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
7838    
7839                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
7840    
7841                    if (orderByComparator != null) {
7842                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7843    
7844                            if (orderByConditionFields.length > 0) {
7845                                    query.append(WHERE_AND);
7846                            }
7847    
7848                            for (int i = 0; i < orderByConditionFields.length; i++) {
7849                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7850                                    query.append(orderByConditionFields[i]);
7851    
7852                                    if ((i + 1) < orderByConditionFields.length) {
7853                                            if (orderByComparator.isAscending() ^ previous) {
7854                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7855                                            }
7856                                            else {
7857                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7858                                            }
7859                                    }
7860                                    else {
7861                                            if (orderByComparator.isAscending() ^ previous) {
7862                                                    query.append(WHERE_GREATER_THAN);
7863                                            }
7864                                            else {
7865                                                    query.append(WHERE_LESSER_THAN);
7866                                            }
7867                                    }
7868                            }
7869    
7870                            query.append(ORDER_BY_CLAUSE);
7871    
7872                            String[] orderByFields = orderByComparator.getOrderByFields();
7873    
7874                            for (int i = 0; i < orderByFields.length; i++) {
7875                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7876                                    query.append(orderByFields[i]);
7877    
7878                                    if ((i + 1) < orderByFields.length) {
7879                                            if (orderByComparator.isAscending() ^ previous) {
7880                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7881                                            }
7882                                            else {
7883                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7884                                            }
7885                                    }
7886                                    else {
7887                                            if (orderByComparator.isAscending() ^ previous) {
7888                                                    query.append(ORDER_BY_ASC);
7889                                            }
7890                                            else {
7891                                                    query.append(ORDER_BY_DESC);
7892                                            }
7893                                    }
7894                            }
7895                    }
7896    
7897                    else {
7898                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7899                    }
7900    
7901                    String sql = query.toString();
7902    
7903                    Query q = session.createQuery(sql);
7904    
7905                    q.setFirstResult(0);
7906                    q.setMaxResults(2);
7907    
7908                    QueryPos qPos = QueryPos.getInstance(q);
7909    
7910                    qPos.add(threadId);
7911    
7912                    qPos.add(parentMessageId);
7913    
7914                    if (orderByComparator != null) {
7915                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7916    
7917                            for (Object value : values) {
7918                                    qPos.add(value);
7919                            }
7920                    }
7921    
7922                    List<MBMessage> list = q.list();
7923    
7924                    if (list.size() == 2) {
7925                            return list.get(1);
7926                    }
7927                    else {
7928                            return null;
7929                    }
7930            }
7931    
7932            /**
7933             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
7934             *
7935             * @param threadId the thread ID
7936             * @param answer the answer
7937             * @return the matching message-boards messages
7938             * @throws SystemException if a system exception occurred
7939             */
7940            public List<MBMessage> findByT_A(long threadId, boolean answer)
7941                    throws SystemException {
7942                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
7943                            QueryUtil.ALL_POS, null);
7944            }
7945    
7946            /**
7947             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
7948             *
7949             * <p>
7950             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7951             * </p>
7952             *
7953             * @param threadId the thread ID
7954             * @param answer the answer
7955             * @param start the lower bound of the range of message-boards messages
7956             * @param end the upper bound of the range of message-boards messages (not inclusive)
7957             * @return the range of matching message-boards messages
7958             * @throws SystemException if a system exception occurred
7959             */
7960            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
7961                    int end) throws SystemException {
7962                    return findByT_A(threadId, answer, start, end, null);
7963            }
7964    
7965            /**
7966             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
7967             *
7968             * <p>
7969             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7970             * </p>
7971             *
7972             * @param threadId the thread ID
7973             * @param answer the answer
7974             * @param start the lower bound of the range of message-boards messages
7975             * @param end the upper bound of the range of message-boards messages (not inclusive)
7976             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7977             * @return the ordered range of matching message-boards messages
7978             * @throws SystemException if a system exception occurred
7979             */
7980            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
7981                    int end, OrderByComparator orderByComparator) throws SystemException {
7982                    FinderPath finderPath = null;
7983                    Object[] finderArgs = null;
7984    
7985                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7986                                    (orderByComparator == null)) {
7987                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
7988                            finderArgs = new Object[] { threadId, answer };
7989                    }
7990                    else {
7991                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
7992                            finderArgs = new Object[] {
7993                                            threadId, answer,
7994                                            
7995                                            start, end, orderByComparator
7996                                    };
7997                    }
7998    
7999                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8000                                    finderArgs, this);
8001    
8002                    if (list == null) {
8003                            StringBundler query = null;
8004    
8005                            if (orderByComparator != null) {
8006                                    query = new StringBundler(4 +
8007                                                    (orderByComparator.getOrderByFields().length * 3));
8008                            }
8009                            else {
8010                                    query = new StringBundler(4);
8011                            }
8012    
8013                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8014    
8015                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
8016    
8017                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
8018    
8019                            if (orderByComparator != null) {
8020                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8021                                            orderByComparator);
8022                            }
8023    
8024                            else {
8025                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8026                            }
8027    
8028                            String sql = query.toString();
8029    
8030                            Session session = null;
8031    
8032                            try {
8033                                    session = openSession();
8034    
8035                                    Query q = session.createQuery(sql);
8036    
8037                                    QueryPos qPos = QueryPos.getInstance(q);
8038    
8039                                    qPos.add(threadId);
8040    
8041                                    qPos.add(answer);
8042    
8043                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8044                                                    end);
8045                            }
8046                            catch (Exception e) {
8047                                    throw processException(e);
8048                            }
8049                            finally {
8050                                    if (list == null) {
8051                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
8052                                    }
8053                                    else {
8054                                            cacheResult(list);
8055    
8056                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
8057                                    }
8058    
8059                                    closeSession(session);
8060                            }
8061                    }
8062    
8063                    return list;
8064            }
8065    
8066            /**
8067             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
8068             *
8069             * <p>
8070             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8071             * </p>
8072             *
8073             * @param threadId the thread ID
8074             * @param answer the answer
8075             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8076             * @return the first matching message-boards message
8077             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8078             * @throws SystemException if a system exception occurred
8079             */
8080            public MBMessage findByT_A_First(long threadId, boolean answer,
8081                    OrderByComparator orderByComparator)
8082                    throws NoSuchMessageException, SystemException {
8083                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
8084                                    orderByComparator);
8085    
8086                    if (list.isEmpty()) {
8087                            StringBundler msg = new StringBundler(6);
8088    
8089                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8090    
8091                            msg.append("threadId=");
8092                            msg.append(threadId);
8093    
8094                            msg.append(", answer=");
8095                            msg.append(answer);
8096    
8097                            msg.append(StringPool.CLOSE_CURLY_BRACE);
8098    
8099                            throw new NoSuchMessageException(msg.toString());
8100                    }
8101                    else {
8102                            return list.get(0);
8103                    }
8104            }
8105    
8106            /**
8107             * Returns the last message-boards message in the ordered set 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 orderByComparator the comparator to order the set by (optionally <code>null</code>)
8116             * @return the last matching message-boards message
8117             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8118             * @throws SystemException if a system exception occurred
8119             */
8120            public MBMessage findByT_A_Last(long threadId, boolean answer,
8121                    OrderByComparator orderByComparator)
8122                    throws NoSuchMessageException, SystemException {
8123                    int count = countByT_A(threadId, answer);
8124    
8125                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
8126                                    orderByComparator);
8127    
8128                    if (list.isEmpty()) {
8129                            StringBundler msg = new StringBundler(6);
8130    
8131                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8132    
8133                            msg.append("threadId=");
8134                            msg.append(threadId);
8135    
8136                            msg.append(", answer=");
8137                            msg.append(answer);
8138    
8139                            msg.append(StringPool.CLOSE_CURLY_BRACE);
8140    
8141                            throw new NoSuchMessageException(msg.toString());
8142                    }
8143                    else {
8144                            return list.get(0);
8145                    }
8146            }
8147    
8148            /**
8149             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
8150             *
8151             * <p>
8152             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8153             * </p>
8154             *
8155             * @param messageId the primary key of the current message-boards message
8156             * @param threadId the thread ID
8157             * @param answer the answer
8158             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8159             * @return the previous, current, and next message-boards message
8160             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8161             * @throws SystemException if a system exception occurred
8162             */
8163            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
8164                    boolean answer, OrderByComparator orderByComparator)
8165                    throws NoSuchMessageException, SystemException {
8166                    MBMessage mbMessage = findByPrimaryKey(messageId);
8167    
8168                    Session session = null;
8169    
8170                    try {
8171                            session = openSession();
8172    
8173                            MBMessage[] array = new MBMessageImpl[3];
8174    
8175                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
8176                                            answer, orderByComparator, true);
8177    
8178                            array[1] = mbMessage;
8179    
8180                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
8181                                            answer, orderByComparator, false);
8182    
8183                            return array;
8184                    }
8185                    catch (Exception e) {
8186                            throw processException(e);
8187                    }
8188                    finally {
8189                            closeSession(session);
8190                    }
8191            }
8192    
8193            protected MBMessage getByT_A_PrevAndNext(Session session,
8194                    MBMessage mbMessage, long threadId, boolean answer,
8195                    OrderByComparator orderByComparator, boolean previous) {
8196                    StringBundler query = null;
8197    
8198                    if (orderByComparator != null) {
8199                            query = new StringBundler(6 +
8200                                            (orderByComparator.getOrderByFields().length * 6));
8201                    }
8202                    else {
8203                            query = new StringBundler(3);
8204                    }
8205    
8206                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8207    
8208                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
8209    
8210                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
8211    
8212                    if (orderByComparator != null) {
8213                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8214    
8215                            if (orderByConditionFields.length > 0) {
8216                                    query.append(WHERE_AND);
8217                            }
8218    
8219                            for (int i = 0; i < orderByConditionFields.length; i++) {
8220                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8221                                    query.append(orderByConditionFields[i]);
8222    
8223                                    if ((i + 1) < orderByConditionFields.length) {
8224                                            if (orderByComparator.isAscending() ^ previous) {
8225                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8226                                            }
8227                                            else {
8228                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8229                                            }
8230                                    }
8231                                    else {
8232                                            if (orderByComparator.isAscending() ^ previous) {
8233                                                    query.append(WHERE_GREATER_THAN);
8234                                            }
8235                                            else {
8236                                                    query.append(WHERE_LESSER_THAN);
8237                                            }
8238                                    }
8239                            }
8240    
8241                            query.append(ORDER_BY_CLAUSE);
8242    
8243                            String[] orderByFields = orderByComparator.getOrderByFields();
8244    
8245                            for (int i = 0; i < orderByFields.length; i++) {
8246                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8247                                    query.append(orderByFields[i]);
8248    
8249                                    if ((i + 1) < orderByFields.length) {
8250                                            if (orderByComparator.isAscending() ^ previous) {
8251                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8252                                            }
8253                                            else {
8254                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8255                                            }
8256                                    }
8257                                    else {
8258                                            if (orderByComparator.isAscending() ^ previous) {
8259                                                    query.append(ORDER_BY_ASC);
8260                                            }
8261                                            else {
8262                                                    query.append(ORDER_BY_DESC);
8263                                            }
8264                                    }
8265                            }
8266                    }
8267    
8268                    else {
8269                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8270                    }
8271    
8272                    String sql = query.toString();
8273    
8274                    Query q = session.createQuery(sql);
8275    
8276                    q.setFirstResult(0);
8277                    q.setMaxResults(2);
8278    
8279                    QueryPos qPos = QueryPos.getInstance(q);
8280    
8281                    qPos.add(threadId);
8282    
8283                    qPos.add(answer);
8284    
8285                    if (orderByComparator != null) {
8286                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8287    
8288                            for (Object value : values) {
8289                                    qPos.add(value);
8290                            }
8291                    }
8292    
8293                    List<MBMessage> list = q.list();
8294    
8295                    if (list.size() == 2) {
8296                            return list.get(1);
8297                    }
8298                    else {
8299                            return null;
8300                    }
8301            }
8302    
8303            /**
8304             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
8305             *
8306             * @param threadId the thread ID
8307             * @param status the status
8308             * @return the matching message-boards messages
8309             * @throws SystemException if a system exception occurred
8310             */
8311            public List<MBMessage> findByT_S(long threadId, int status)
8312                    throws SystemException {
8313                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
8314                            QueryUtil.ALL_POS, null);
8315            }
8316    
8317            /**
8318             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
8319             *
8320             * <p>
8321             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8322             * </p>
8323             *
8324             * @param threadId the thread ID
8325             * @param status the status
8326             * @param start the lower bound of the range of message-boards messages
8327             * @param end the upper bound of the range of message-boards messages (not inclusive)
8328             * @return the range of matching message-boards messages
8329             * @throws SystemException if a system exception occurred
8330             */
8331            public List<MBMessage> findByT_S(long threadId, int status, int start,
8332                    int end) throws SystemException {
8333                    return findByT_S(threadId, status, start, end, null);
8334            }
8335    
8336            /**
8337             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
8338             *
8339             * <p>
8340             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8341             * </p>
8342             *
8343             * @param threadId the thread ID
8344             * @param status the status
8345             * @param start the lower bound of the range of message-boards messages
8346             * @param end the upper bound of the range of message-boards messages (not inclusive)
8347             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8348             * @return the ordered range of matching message-boards messages
8349             * @throws SystemException if a system exception occurred
8350             */
8351            public List<MBMessage> findByT_S(long threadId, int status, int start,
8352                    int end, OrderByComparator orderByComparator) throws SystemException {
8353                    FinderPath finderPath = null;
8354                    Object[] finderArgs = null;
8355    
8356                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8357                                    (orderByComparator == null)) {
8358                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
8359                            finderArgs = new Object[] { threadId, status };
8360                    }
8361                    else {
8362                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
8363                            finderArgs = new Object[] {
8364                                            threadId, status,
8365                                            
8366                                            start, end, orderByComparator
8367                                    };
8368                    }
8369    
8370                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8371                                    finderArgs, this);
8372    
8373                    if (list == null) {
8374                            StringBundler query = null;
8375    
8376                            if (orderByComparator != null) {
8377                                    query = new StringBundler(4 +
8378                                                    (orderByComparator.getOrderByFields().length * 3));
8379                            }
8380                            else {
8381                                    query = new StringBundler(4);
8382                            }
8383    
8384                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8385    
8386                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
8387    
8388                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
8389    
8390                            if (orderByComparator != null) {
8391                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8392                                            orderByComparator);
8393                            }
8394    
8395                            else {
8396                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8397                            }
8398    
8399                            String sql = query.toString();
8400    
8401                            Session session = null;
8402    
8403                            try {
8404                                    session = openSession();
8405    
8406                                    Query q = session.createQuery(sql);
8407    
8408                                    QueryPos qPos = QueryPos.getInstance(q);
8409    
8410                                    qPos.add(threadId);
8411    
8412                                    qPos.add(status);
8413    
8414                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8415                                                    end);
8416                            }
8417                            catch (Exception e) {
8418                                    throw processException(e);
8419                            }
8420                            finally {
8421                                    if (list == null) {
8422                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
8423                                    }
8424                                    else {
8425                                            cacheResult(list);
8426    
8427                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
8428                                    }
8429    
8430                                    closeSession(session);
8431                            }
8432                    }
8433    
8434                    return list;
8435            }
8436    
8437            /**
8438             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
8439             *
8440             * <p>
8441             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8442             * </p>
8443             *
8444             * @param threadId the thread ID
8445             * @param status the status
8446             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8447             * @return the first matching message-boards message
8448             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8449             * @throws SystemException if a system exception occurred
8450             */
8451            public MBMessage findByT_S_First(long threadId, int status,
8452                    OrderByComparator orderByComparator)
8453                    throws NoSuchMessageException, SystemException {
8454                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
8455                                    orderByComparator);
8456    
8457                    if (list.isEmpty()) {
8458                            StringBundler msg = new StringBundler(6);
8459    
8460                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8461    
8462                            msg.append("threadId=");
8463                            msg.append(threadId);
8464    
8465                            msg.append(", status=");
8466                            msg.append(status);
8467    
8468                            msg.append(StringPool.CLOSE_CURLY_BRACE);
8469    
8470                            throw new NoSuchMessageException(msg.toString());
8471                    }
8472                    else {
8473                            return list.get(0);
8474                    }
8475            }
8476    
8477            /**
8478             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
8479             *
8480             * <p>
8481             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8482             * </p>
8483             *
8484             * @param threadId the thread ID
8485             * @param status the status
8486             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8487             * @return the last matching message-boards message
8488             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8489             * @throws SystemException if a system exception occurred
8490             */
8491            public MBMessage findByT_S_Last(long threadId, int status,
8492                    OrderByComparator orderByComparator)
8493                    throws NoSuchMessageException, SystemException {
8494                    int count = countByT_S(threadId, status);
8495    
8496                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
8497                                    orderByComparator);
8498    
8499                    if (list.isEmpty()) {
8500                            StringBundler msg = new StringBundler(6);
8501    
8502                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8503    
8504                            msg.append("threadId=");
8505                            msg.append(threadId);
8506    
8507                            msg.append(", status=");
8508                            msg.append(status);
8509    
8510                            msg.append(StringPool.CLOSE_CURLY_BRACE);
8511    
8512                            throw new NoSuchMessageException(msg.toString());
8513                    }
8514                    else {
8515                            return list.get(0);
8516                    }
8517            }
8518    
8519            /**
8520             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
8521             *
8522             * <p>
8523             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8524             * </p>
8525             *
8526             * @param messageId the primary key of the current message-boards message
8527             * @param threadId the thread ID
8528             * @param status the status
8529             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8530             * @return the previous, current, and next message-boards message
8531             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8532             * @throws SystemException if a system exception occurred
8533             */
8534            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
8535                    int status, OrderByComparator orderByComparator)
8536                    throws NoSuchMessageException, SystemException {
8537                    MBMessage mbMessage = findByPrimaryKey(messageId);
8538    
8539                    Session session = null;
8540    
8541                    try {
8542                            session = openSession();
8543    
8544                            MBMessage[] array = new MBMessageImpl[3];
8545    
8546                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
8547                                            status, orderByComparator, true);
8548    
8549                            array[1] = mbMessage;
8550    
8551                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
8552                                            status, orderByComparator, false);
8553    
8554                            return array;
8555                    }
8556                    catch (Exception e) {
8557                            throw processException(e);
8558                    }
8559                    finally {
8560                            closeSession(session);
8561                    }
8562            }
8563    
8564            protected MBMessage getByT_S_PrevAndNext(Session session,
8565                    MBMessage mbMessage, long threadId, int status,
8566                    OrderByComparator orderByComparator, boolean previous) {
8567                    StringBundler query = null;
8568    
8569                    if (orderByComparator != null) {
8570                            query = new StringBundler(6 +
8571                                            (orderByComparator.getOrderByFields().length * 6));
8572                    }
8573                    else {
8574                            query = new StringBundler(3);
8575                    }
8576    
8577                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8578    
8579                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
8580    
8581                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
8582    
8583                    if (orderByComparator != null) {
8584                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8585    
8586                            if (orderByConditionFields.length > 0) {
8587                                    query.append(WHERE_AND);
8588                            }
8589    
8590                            for (int i = 0; i < orderByConditionFields.length; i++) {
8591                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8592                                    query.append(orderByConditionFields[i]);
8593    
8594                                    if ((i + 1) < orderByConditionFields.length) {
8595                                            if (orderByComparator.isAscending() ^ previous) {
8596                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8597                                            }
8598                                            else {
8599                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8600                                            }
8601                                    }
8602                                    else {
8603                                            if (orderByComparator.isAscending() ^ previous) {
8604                                                    query.append(WHERE_GREATER_THAN);
8605                                            }
8606                                            else {
8607                                                    query.append(WHERE_LESSER_THAN);
8608                                            }
8609                                    }
8610                            }
8611    
8612                            query.append(ORDER_BY_CLAUSE);
8613    
8614                            String[] orderByFields = orderByComparator.getOrderByFields();
8615    
8616                            for (int i = 0; i < orderByFields.length; i++) {
8617                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8618                                    query.append(orderByFields[i]);
8619    
8620                                    if ((i + 1) < orderByFields.length) {
8621                                            if (orderByComparator.isAscending() ^ previous) {
8622                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8623                                            }
8624                                            else {
8625                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8626                                            }
8627                                    }
8628                                    else {
8629                                            if (orderByComparator.isAscending() ^ previous) {
8630                                                    query.append(ORDER_BY_ASC);
8631                                            }
8632                                            else {
8633                                                    query.append(ORDER_BY_DESC);
8634                                            }
8635                                    }
8636                            }
8637                    }
8638    
8639                    else {
8640                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8641                    }
8642    
8643                    String sql = query.toString();
8644    
8645                    Query q = session.createQuery(sql);
8646    
8647                    q.setFirstResult(0);
8648                    q.setMaxResults(2);
8649    
8650                    QueryPos qPos = QueryPos.getInstance(q);
8651    
8652                    qPos.add(threadId);
8653    
8654                    qPos.add(status);
8655    
8656                    if (orderByComparator != null) {
8657                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8658    
8659                            for (Object value : values) {
8660                                    qPos.add(value);
8661                            }
8662                    }
8663    
8664                    List<MBMessage> list = q.list();
8665    
8666                    if (list.size() == 2) {
8667                            return list.get(1);
8668                    }
8669                    else {
8670                            return null;
8671                    }
8672            }
8673    
8674            /**
8675             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
8676             *
8677             * @param threadId the thread ID
8678             * @param status the status
8679             * @return the matching message-boards messages
8680             * @throws SystemException if a system exception occurred
8681             */
8682            public List<MBMessage> findByTR_S(long threadId, int status)
8683                    throws SystemException {
8684                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
8685                            QueryUtil.ALL_POS, null);
8686            }
8687    
8688            /**
8689             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
8690             *
8691             * <p>
8692             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8693             * </p>
8694             *
8695             * @param threadId the thread ID
8696             * @param status the status
8697             * @param start the lower bound of the range of message-boards messages
8698             * @param end the upper bound of the range of message-boards messages (not inclusive)
8699             * @return the range of matching message-boards messages
8700             * @throws SystemException if a system exception occurred
8701             */
8702            public List<MBMessage> findByTR_S(long threadId, int status, int start,
8703                    int end) throws SystemException {
8704                    return findByTR_S(threadId, status, start, end, null);
8705            }
8706    
8707            /**
8708             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
8709             *
8710             * <p>
8711             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8712             * </p>
8713             *
8714             * @param threadId the thread ID
8715             * @param status the status
8716             * @param start the lower bound of the range of message-boards messages
8717             * @param end the upper bound of the range of message-boards messages (not inclusive)
8718             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8719             * @return the ordered range of matching message-boards messages
8720             * @throws SystemException if a system exception occurred
8721             */
8722            public List<MBMessage> findByTR_S(long threadId, int status, int start,
8723                    int end, OrderByComparator orderByComparator) throws SystemException {
8724                    FinderPath finderPath = null;
8725                    Object[] finderArgs = null;
8726    
8727                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8728                                    (orderByComparator == null)) {
8729                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
8730                            finderArgs = new Object[] { threadId, status };
8731                    }
8732                    else {
8733                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
8734                            finderArgs = new Object[] {
8735                                            threadId, status,
8736                                            
8737                                            start, end, orderByComparator
8738                                    };
8739                    }
8740    
8741                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8742                                    finderArgs, this);
8743    
8744                    if (list == null) {
8745                            StringBundler query = null;
8746    
8747                            if (orderByComparator != null) {
8748                                    query = new StringBundler(4 +
8749                                                    (orderByComparator.getOrderByFields().length * 3));
8750                            }
8751                            else {
8752                                    query = new StringBundler(4);
8753                            }
8754    
8755                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8756    
8757                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
8758    
8759                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
8760    
8761                            if (orderByComparator != null) {
8762                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8763                                            orderByComparator);
8764                            }
8765    
8766                            else {
8767                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8768                            }
8769    
8770                            String sql = query.toString();
8771    
8772                            Session session = null;
8773    
8774                            try {
8775                                    session = openSession();
8776    
8777                                    Query q = session.createQuery(sql);
8778    
8779                                    QueryPos qPos = QueryPos.getInstance(q);
8780    
8781                                    qPos.add(threadId);
8782    
8783                                    qPos.add(status);
8784    
8785                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8786                                                    end);
8787                            }
8788                            catch (Exception e) {
8789                                    throw processException(e);
8790                            }
8791                            finally {
8792                                    if (list == null) {
8793                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
8794                                    }
8795                                    else {
8796                                            cacheResult(list);
8797    
8798                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
8799                                    }
8800    
8801                                    closeSession(session);
8802                            }
8803                    }
8804    
8805                    return list;
8806            }
8807    
8808            /**
8809             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
8810             *
8811             * <p>
8812             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8813             * </p>
8814             *
8815             * @param threadId the thread ID
8816             * @param status the status
8817             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8818             * @return the first matching message-boards message
8819             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8820             * @throws SystemException if a system exception occurred
8821             */
8822            public MBMessage findByTR_S_First(long threadId, int status,
8823                    OrderByComparator orderByComparator)
8824                    throws NoSuchMessageException, SystemException {
8825                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
8826                                    orderByComparator);
8827    
8828                    if (list.isEmpty()) {
8829                            StringBundler msg = new StringBundler(6);
8830    
8831                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8832    
8833                            msg.append("threadId=");
8834                            msg.append(threadId);
8835    
8836                            msg.append(", status=");
8837                            msg.append(status);
8838    
8839                            msg.append(StringPool.CLOSE_CURLY_BRACE);
8840    
8841                            throw new NoSuchMessageException(msg.toString());
8842                    }
8843                    else {
8844                            return list.get(0);
8845                    }
8846            }
8847    
8848            /**
8849             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
8850             *
8851             * <p>
8852             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8853             * </p>
8854             *
8855             * @param threadId the thread ID
8856             * @param status the status
8857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8858             * @return the last matching message-boards message
8859             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8860             * @throws SystemException if a system exception occurred
8861             */
8862            public MBMessage findByTR_S_Last(long threadId, int status,
8863                    OrderByComparator orderByComparator)
8864                    throws NoSuchMessageException, SystemException {
8865                    int count = countByTR_S(threadId, status);
8866    
8867                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
8868                                    orderByComparator);
8869    
8870                    if (list.isEmpty()) {
8871                            StringBundler msg = new StringBundler(6);
8872    
8873                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8874    
8875                            msg.append("threadId=");
8876                            msg.append(threadId);
8877    
8878                            msg.append(", status=");
8879                            msg.append(status);
8880    
8881                            msg.append(StringPool.CLOSE_CURLY_BRACE);
8882    
8883                            throw new NoSuchMessageException(msg.toString());
8884                    }
8885                    else {
8886                            return list.get(0);
8887                    }
8888            }
8889    
8890            /**
8891             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
8892             *
8893             * <p>
8894             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8895             * </p>
8896             *
8897             * @param messageId the primary key of the current message-boards message
8898             * @param threadId the thread ID
8899             * @param status the status
8900             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8901             * @return the previous, current, and next message-boards message
8902             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8903             * @throws SystemException if a system exception occurred
8904             */
8905            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
8906                    int status, OrderByComparator orderByComparator)
8907                    throws NoSuchMessageException, SystemException {
8908                    MBMessage mbMessage = findByPrimaryKey(messageId);
8909    
8910                    Session session = null;
8911    
8912                    try {
8913                            session = openSession();
8914    
8915                            MBMessage[] array = new MBMessageImpl[3];
8916    
8917                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
8918                                            status, orderByComparator, true);
8919    
8920                            array[1] = mbMessage;
8921    
8922                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
8923                                            status, orderByComparator, false);
8924    
8925                            return array;
8926                    }
8927                    catch (Exception e) {
8928                            throw processException(e);
8929                    }
8930                    finally {
8931                            closeSession(session);
8932                    }
8933            }
8934    
8935            protected MBMessage getByTR_S_PrevAndNext(Session session,
8936                    MBMessage mbMessage, long threadId, int status,
8937                    OrderByComparator orderByComparator, boolean previous) {
8938                    StringBundler query = null;
8939    
8940                    if (orderByComparator != null) {
8941                            query = new StringBundler(6 +
8942                                            (orderByComparator.getOrderByFields().length * 6));
8943                    }
8944                    else {
8945                            query = new StringBundler(3);
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                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8956    
8957                            if (orderByConditionFields.length > 0) {
8958                                    query.append(WHERE_AND);
8959                            }
8960    
8961                            for (int i = 0; i < orderByConditionFields.length; i++) {
8962                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8963                                    query.append(orderByConditionFields[i]);
8964    
8965                                    if ((i + 1) < orderByConditionFields.length) {
8966                                            if (orderByComparator.isAscending() ^ previous) {
8967                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8968                                            }
8969                                            else {
8970                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8971                                            }
8972                                    }
8973                                    else {
8974                                            if (orderByComparator.isAscending() ^ previous) {
8975                                                    query.append(WHERE_GREATER_THAN);
8976                                            }
8977                                            else {
8978                                                    query.append(WHERE_LESSER_THAN);
8979                                            }
8980                                    }
8981                            }
8982    
8983                            query.append(ORDER_BY_CLAUSE);
8984    
8985                            String[] orderByFields = orderByComparator.getOrderByFields();
8986    
8987                            for (int i = 0; i < orderByFields.length; i++) {
8988                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8989                                    query.append(orderByFields[i]);
8990    
8991                                    if ((i + 1) < orderByFields.length) {
8992                                            if (orderByComparator.isAscending() ^ previous) {
8993                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8994                                            }
8995                                            else {
8996                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8997                                            }
8998                                    }
8999                                    else {
9000                                            if (orderByComparator.isAscending() ^ previous) {
9001                                                    query.append(ORDER_BY_ASC);
9002                                            }
9003                                            else {
9004                                                    query.append(ORDER_BY_DESC);
9005                                            }
9006                                    }
9007                            }
9008                    }
9009    
9010                    else {
9011                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9012                    }
9013    
9014                    String sql = query.toString();
9015    
9016                    Query q = session.createQuery(sql);
9017    
9018                    q.setFirstResult(0);
9019                    q.setMaxResults(2);
9020    
9021                    QueryPos qPos = QueryPos.getInstance(q);
9022    
9023                    qPos.add(threadId);
9024    
9025                    qPos.add(status);
9026    
9027                    if (orderByComparator != null) {
9028                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9029    
9030                            for (Object value : values) {
9031                                    qPos.add(value);
9032                            }
9033                    }
9034    
9035                    List<MBMessage> list = q.list();
9036    
9037                    if (list.size() == 2) {
9038                            return list.get(1);
9039                    }
9040                    else {
9041                            return null;
9042                    }
9043            }
9044    
9045            /**
9046             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
9047             *
9048             * @param groupId the group ID
9049             * @param userId the user ID
9050             * @param status the status
9051             * @return the matching message-boards messages
9052             * @throws SystemException if a system exception occurred
9053             */
9054            public List<MBMessage> findByG_U_S(long groupId, long userId, int status)
9055                    throws SystemException {
9056                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
9057                            QueryUtil.ALL_POS, null);
9058            }
9059    
9060            /**
9061             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
9062             *
9063             * <p>
9064             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9065             * </p>
9066             *
9067             * @param groupId the group ID
9068             * @param userId the user ID
9069             * @param status the status
9070             * @param start the lower bound of the range of message-boards messages
9071             * @param end the upper bound of the range of message-boards messages (not inclusive)
9072             * @return the range of matching message-boards messages
9073             * @throws SystemException if a system exception occurred
9074             */
9075            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
9076                    int start, int end) throws SystemException {
9077                    return findByG_U_S(groupId, userId, status, start, end, null);
9078            }
9079    
9080            /**
9081             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
9082             *
9083             * <p>
9084             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9085             * </p>
9086             *
9087             * @param groupId the group ID
9088             * @param userId the user ID
9089             * @param status the status
9090             * @param start the lower bound of the range of message-boards messages
9091             * @param end the upper bound of the range of message-boards messages (not inclusive)
9092             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9093             * @return the ordered range of matching message-boards messages
9094             * @throws SystemException if a system exception occurred
9095             */
9096            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
9097                    int start, int end, OrderByComparator orderByComparator)
9098                    throws SystemException {
9099                    FinderPath finderPath = null;
9100                    Object[] finderArgs = null;
9101    
9102                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9103                                    (orderByComparator == null)) {
9104                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
9105                            finderArgs = new Object[] { groupId, userId, status };
9106                    }
9107                    else {
9108                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
9109                            finderArgs = new Object[] {
9110                                            groupId, userId, status,
9111                                            
9112                                            start, end, orderByComparator
9113                                    };
9114                    }
9115    
9116                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9117                                    finderArgs, this);
9118    
9119                    if (list == null) {
9120                            StringBundler query = null;
9121    
9122                            if (orderByComparator != null) {
9123                                    query = new StringBundler(5 +
9124                                                    (orderByComparator.getOrderByFields().length * 3));
9125                            }
9126                            else {
9127                                    query = new StringBundler(5);
9128                            }
9129    
9130                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9131    
9132                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
9133    
9134                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
9135    
9136                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
9137    
9138                            if (orderByComparator != null) {
9139                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9140                                            orderByComparator);
9141                            }
9142    
9143                            else {
9144                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9145                            }
9146    
9147                            String sql = query.toString();
9148    
9149                            Session session = null;
9150    
9151                            try {
9152                                    session = openSession();
9153    
9154                                    Query q = session.createQuery(sql);
9155    
9156                                    QueryPos qPos = QueryPos.getInstance(q);
9157    
9158                                    qPos.add(groupId);
9159    
9160                                    qPos.add(userId);
9161    
9162                                    qPos.add(status);
9163    
9164                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
9165                                                    end);
9166                            }
9167                            catch (Exception e) {
9168                                    throw processException(e);
9169                            }
9170                            finally {
9171                                    if (list == null) {
9172                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
9173                                    }
9174                                    else {
9175                                            cacheResult(list);
9176    
9177                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
9178                                    }
9179    
9180                                    closeSession(session);
9181                            }
9182                    }
9183    
9184                    return list;
9185            }
9186    
9187            /**
9188             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
9189             *
9190             * <p>
9191             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9192             * </p>
9193             *
9194             * @param groupId the group ID
9195             * @param userId the user ID
9196             * @param status the status
9197             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9198             * @return the first matching message-boards message
9199             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9200             * @throws SystemException if a system exception occurred
9201             */
9202            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
9203                    OrderByComparator orderByComparator)
9204                    throws NoSuchMessageException, SystemException {
9205                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
9206                                    orderByComparator);
9207    
9208                    if (list.isEmpty()) {
9209                            StringBundler msg = new StringBundler(8);
9210    
9211                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9212    
9213                            msg.append("groupId=");
9214                            msg.append(groupId);
9215    
9216                            msg.append(", userId=");
9217                            msg.append(userId);
9218    
9219                            msg.append(", status=");
9220                            msg.append(status);
9221    
9222                            msg.append(StringPool.CLOSE_CURLY_BRACE);
9223    
9224                            throw new NoSuchMessageException(msg.toString());
9225                    }
9226                    else {
9227                            return list.get(0);
9228                    }
9229            }
9230    
9231            /**
9232             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
9233             *
9234             * <p>
9235             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9236             * </p>
9237             *
9238             * @param groupId the group ID
9239             * @param userId the user ID
9240             * @param status the status
9241             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9242             * @return the last matching message-boards message
9243             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9244             * @throws SystemException if a system exception occurred
9245             */
9246            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
9247                    OrderByComparator orderByComparator)
9248                    throws NoSuchMessageException, SystemException {
9249                    int count = countByG_U_S(groupId, userId, status);
9250    
9251                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
9252                                    count, orderByComparator);
9253    
9254                    if (list.isEmpty()) {
9255                            StringBundler msg = new StringBundler(8);
9256    
9257                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9258    
9259                            msg.append("groupId=");
9260                            msg.append(groupId);
9261    
9262                            msg.append(", userId=");
9263                            msg.append(userId);
9264    
9265                            msg.append(", status=");
9266                            msg.append(status);
9267    
9268                            msg.append(StringPool.CLOSE_CURLY_BRACE);
9269    
9270                            throw new NoSuchMessageException(msg.toString());
9271                    }
9272                    else {
9273                            return list.get(0);
9274                    }
9275            }
9276    
9277            /**
9278             * 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;.
9279             *
9280             * <p>
9281             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9282             * </p>
9283             *
9284             * @param messageId the primary key of the current message-boards message
9285             * @param groupId the group ID
9286             * @param userId the user ID
9287             * @param status the status
9288             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9289             * @return the previous, current, and next message-boards message
9290             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9291             * @throws SystemException if a system exception occurred
9292             */
9293            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
9294                    long userId, int status, OrderByComparator orderByComparator)
9295                    throws NoSuchMessageException, SystemException {
9296                    MBMessage mbMessage = findByPrimaryKey(messageId);
9297    
9298                    Session session = null;
9299    
9300                    try {
9301                            session = openSession();
9302    
9303                            MBMessage[] array = new MBMessageImpl[3];
9304    
9305                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
9306                                            userId, status, orderByComparator, true);
9307    
9308                            array[1] = mbMessage;
9309    
9310                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
9311                                            userId, status, orderByComparator, false);
9312    
9313                            return array;
9314                    }
9315                    catch (Exception e) {
9316                            throw processException(e);
9317                    }
9318                    finally {
9319                            closeSession(session);
9320                    }
9321            }
9322    
9323            protected MBMessage getByG_U_S_PrevAndNext(Session session,
9324                    MBMessage mbMessage, long groupId, long userId, int status,
9325                    OrderByComparator orderByComparator, boolean previous) {
9326                    StringBundler query = null;
9327    
9328                    if (orderByComparator != null) {
9329                            query = new StringBundler(6 +
9330                                            (orderByComparator.getOrderByFields().length * 6));
9331                    }
9332                    else {
9333                            query = new StringBundler(3);
9334                    }
9335    
9336                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9337    
9338                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
9339    
9340                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
9341    
9342                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
9343    
9344                    if (orderByComparator != null) {
9345                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9346    
9347                            if (orderByConditionFields.length > 0) {
9348                                    query.append(WHERE_AND);
9349                            }
9350    
9351                            for (int i = 0; i < orderByConditionFields.length; i++) {
9352                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9353                                    query.append(orderByConditionFields[i]);
9354    
9355                                    if ((i + 1) < orderByConditionFields.length) {
9356                                            if (orderByComparator.isAscending() ^ previous) {
9357                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9358                                            }
9359                                            else {
9360                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9361                                            }
9362                                    }
9363                                    else {
9364                                            if (orderByComparator.isAscending() ^ previous) {
9365                                                    query.append(WHERE_GREATER_THAN);
9366                                            }
9367                                            else {
9368                                                    query.append(WHERE_LESSER_THAN);
9369                                            }
9370                                    }
9371                            }
9372    
9373                            query.append(ORDER_BY_CLAUSE);
9374    
9375                            String[] orderByFields = orderByComparator.getOrderByFields();
9376    
9377                            for (int i = 0; i < orderByFields.length; i++) {
9378                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9379                                    query.append(orderByFields[i]);
9380    
9381                                    if ((i + 1) < orderByFields.length) {
9382                                            if (orderByComparator.isAscending() ^ previous) {
9383                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9384                                            }
9385                                            else {
9386                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9387                                            }
9388                                    }
9389                                    else {
9390                                            if (orderByComparator.isAscending() ^ previous) {
9391                                                    query.append(ORDER_BY_ASC);
9392                                            }
9393                                            else {
9394                                                    query.append(ORDER_BY_DESC);
9395                                            }
9396                                    }
9397                            }
9398                    }
9399    
9400                    else {
9401                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9402                    }
9403    
9404                    String sql = query.toString();
9405    
9406                    Query q = session.createQuery(sql);
9407    
9408                    q.setFirstResult(0);
9409                    q.setMaxResults(2);
9410    
9411                    QueryPos qPos = QueryPos.getInstance(q);
9412    
9413                    qPos.add(groupId);
9414    
9415                    qPos.add(userId);
9416    
9417                    qPos.add(status);
9418    
9419                    if (orderByComparator != null) {
9420                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9421    
9422                            for (Object value : values) {
9423                                    qPos.add(value);
9424                            }
9425                    }
9426    
9427                    List<MBMessage> list = q.list();
9428    
9429                    if (list.size() == 2) {
9430                            return list.get(1);
9431                    }
9432                    else {
9433                            return null;
9434                    }
9435            }
9436    
9437            /**
9438             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
9439             *
9440             * @param groupId the group ID
9441             * @param userId the user ID
9442             * @param status the status
9443             * @return the matching message-boards messages that the user has permission to view
9444             * @throws SystemException if a system exception occurred
9445             */
9446            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
9447                    int status) throws SystemException {
9448                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
9449                            QueryUtil.ALL_POS, null);
9450            }
9451    
9452            /**
9453             * 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;.
9454             *
9455             * <p>
9456             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9457             * </p>
9458             *
9459             * @param groupId the group ID
9460             * @param userId the user ID
9461             * @param status the status
9462             * @param start the lower bound of the range of message-boards messages
9463             * @param end the upper bound of the range of message-boards messages (not inclusive)
9464             * @return the range of matching message-boards messages that the user has permission to view
9465             * @throws SystemException if a system exception occurred
9466             */
9467            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
9468                    int status, int start, int end) throws SystemException {
9469                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
9470            }
9471    
9472            /**
9473             * 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;.
9474             *
9475             * <p>
9476             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9477             * </p>
9478             *
9479             * @param groupId the group ID
9480             * @param userId the user ID
9481             * @param status the status
9482             * @param start the lower bound of the range of message-boards messages
9483             * @param end the upper bound of the range of message-boards messages (not inclusive)
9484             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9485             * @return the ordered range of matching message-boards messages that the user has permission to view
9486             * @throws SystemException if a system exception occurred
9487             */
9488            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
9489                    int status, int start, int end, OrderByComparator orderByComparator)
9490                    throws SystemException {
9491                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9492                            return findByG_U_S(groupId, userId, status, start, end,
9493                                    orderByComparator);
9494                    }
9495    
9496                    StringBundler query = null;
9497    
9498                    if (orderByComparator != null) {
9499                            query = new StringBundler(5 +
9500                                            (orderByComparator.getOrderByFields().length * 3));
9501                    }
9502                    else {
9503                            query = new StringBundler(5);
9504                    }
9505    
9506                    if (getDB().isSupportsInlineDistinct()) {
9507                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
9508                    }
9509                    else {
9510                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
9511                    }
9512    
9513                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
9514    
9515                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
9516    
9517                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
9518    
9519                    if (!getDB().isSupportsInlineDistinct()) {
9520                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
9521                    }
9522    
9523                    if (orderByComparator != null) {
9524                            if (getDB().isSupportsInlineDistinct()) {
9525                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9526                                            orderByComparator);
9527                            }
9528                            else {
9529                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
9530                                            orderByComparator);
9531                            }
9532                    }
9533    
9534                    else {
9535                            if (getDB().isSupportsInlineDistinct()) {
9536                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9537                            }
9538                            else {
9539                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
9540                            }
9541                    }
9542    
9543                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9544                                    MBMessage.class.getName(),
9545                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9546    
9547                    Session session = null;
9548    
9549                    try {
9550                            session = openSession();
9551    
9552                            SQLQuery q = session.createSQLQuery(sql);
9553    
9554                            if (getDB().isSupportsInlineDistinct()) {
9555                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
9556                            }
9557                            else {
9558                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
9559                            }
9560    
9561                            QueryPos qPos = QueryPos.getInstance(q);
9562    
9563                            qPos.add(groupId);
9564    
9565                            qPos.add(userId);
9566    
9567                            qPos.add(status);
9568    
9569                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
9570                    }
9571                    catch (Exception e) {
9572                            throw processException(e);
9573                    }
9574                    finally {
9575                            closeSession(session);
9576                    }
9577            }
9578    
9579            /**
9580             * 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;.
9581             *
9582             * @param messageId the primary key of the current message-boards message
9583             * @param groupId the group ID
9584             * @param userId the user ID
9585             * @param status the status
9586             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9587             * @return the previous, current, and next message-boards message
9588             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9589             * @throws SystemException if a system exception occurred
9590             */
9591            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
9592                    long groupId, long userId, int status,
9593                    OrderByComparator orderByComparator)
9594                    throws NoSuchMessageException, SystemException {
9595                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9596                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
9597                                    orderByComparator);
9598                    }
9599    
9600                    MBMessage mbMessage = findByPrimaryKey(messageId);
9601    
9602                    Session session = null;
9603    
9604                    try {
9605                            session = openSession();
9606    
9607                            MBMessage[] array = new MBMessageImpl[3];
9608    
9609                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
9610                                            groupId, userId, status, orderByComparator, true);
9611    
9612                            array[1] = mbMessage;
9613    
9614                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
9615                                            groupId, userId, status, orderByComparator, false);
9616    
9617                            return array;
9618                    }
9619                    catch (Exception e) {
9620                            throw processException(e);
9621                    }
9622                    finally {
9623                            closeSession(session);
9624                    }
9625            }
9626    
9627            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
9628                    MBMessage mbMessage, long groupId, long userId, int status,
9629                    OrderByComparator orderByComparator, boolean previous) {
9630                    StringBundler query = null;
9631    
9632                    if (orderByComparator != null) {
9633                            query = new StringBundler(6 +
9634                                            (orderByComparator.getOrderByFields().length * 6));
9635                    }
9636                    else {
9637                            query = new StringBundler(3);
9638                    }
9639    
9640                    if (getDB().isSupportsInlineDistinct()) {
9641                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
9642                    }
9643                    else {
9644                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
9645                    }
9646    
9647                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
9648    
9649                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
9650    
9651                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
9652    
9653                    if (!getDB().isSupportsInlineDistinct()) {
9654                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
9655                    }
9656    
9657                    if (orderByComparator != null) {
9658                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9659    
9660                            if (orderByConditionFields.length > 0) {
9661                                    query.append(WHERE_AND);
9662                            }
9663    
9664                            for (int i = 0; i < orderByConditionFields.length; i++) {
9665                                    if (getDB().isSupportsInlineDistinct()) {
9666                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9667                                    }
9668                                    else {
9669                                            query.append(_ORDER_BY_ENTITY_TABLE);
9670                                    }
9671    
9672                                    query.append(orderByConditionFields[i]);
9673    
9674                                    if ((i + 1) < orderByConditionFields.length) {
9675                                            if (orderByComparator.isAscending() ^ previous) {
9676                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9677                                            }
9678                                            else {
9679                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9680                                            }
9681                                    }
9682                                    else {
9683                                            if (orderByComparator.isAscending() ^ previous) {
9684                                                    query.append(WHERE_GREATER_THAN);
9685                                            }
9686                                            else {
9687                                                    query.append(WHERE_LESSER_THAN);
9688                                            }
9689                                    }
9690                            }
9691    
9692                            query.append(ORDER_BY_CLAUSE);
9693    
9694                            String[] orderByFields = orderByComparator.getOrderByFields();
9695    
9696                            for (int i = 0; i < orderByFields.length; i++) {
9697                                    if (getDB().isSupportsInlineDistinct()) {
9698                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9699                                    }
9700                                    else {
9701                                            query.append(_ORDER_BY_ENTITY_TABLE);
9702                                    }
9703    
9704                                    query.append(orderByFields[i]);
9705    
9706                                    if ((i + 1) < orderByFields.length) {
9707                                            if (orderByComparator.isAscending() ^ previous) {
9708                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9709                                            }
9710                                            else {
9711                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9712                                            }
9713                                    }
9714                                    else {
9715                                            if (orderByComparator.isAscending() ^ previous) {
9716                                                    query.append(ORDER_BY_ASC);
9717                                            }
9718                                            else {
9719                                                    query.append(ORDER_BY_DESC);
9720                                            }
9721                                    }
9722                            }
9723                    }
9724    
9725                    else {
9726                            if (getDB().isSupportsInlineDistinct()) {
9727                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9728                            }
9729                            else {
9730                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
9731                            }
9732                    }
9733    
9734                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9735                                    MBMessage.class.getName(),
9736                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9737    
9738                    SQLQuery q = session.createSQLQuery(sql);
9739    
9740                    q.setFirstResult(0);
9741                    q.setMaxResults(2);
9742    
9743                    if (getDB().isSupportsInlineDistinct()) {
9744                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
9745                    }
9746                    else {
9747                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
9748                    }
9749    
9750                    QueryPos qPos = QueryPos.getInstance(q);
9751    
9752                    qPos.add(groupId);
9753    
9754                    qPos.add(userId);
9755    
9756                    qPos.add(status);
9757    
9758                    if (orderByComparator != null) {
9759                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9760    
9761                            for (Object value : values) {
9762                                    qPos.add(value);
9763                            }
9764                    }
9765    
9766                    List<MBMessage> list = q.list();
9767    
9768                    if (list.size() == 2) {
9769                            return list.get(1);
9770                    }
9771                    else {
9772                            return null;
9773                    }
9774            }
9775    
9776            /**
9777             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
9778             *
9779             * @param groupId the group ID
9780             * @param categoryId the category ID
9781             * @param threadId the thread ID
9782             * @return the matching message-boards messages
9783             * @throws SystemException if a system exception occurred
9784             */
9785            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
9786                    long threadId) throws SystemException {
9787                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
9788                            QueryUtil.ALL_POS, null);
9789            }
9790    
9791            /**
9792             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
9793             *
9794             * <p>
9795             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9796             * </p>
9797             *
9798             * @param groupId the group ID
9799             * @param categoryId the category ID
9800             * @param threadId the thread ID
9801             * @param start the lower bound of the range of message-boards messages
9802             * @param end the upper bound of the range of message-boards messages (not inclusive)
9803             * @return the range of matching message-boards messages
9804             * @throws SystemException if a system exception occurred
9805             */
9806            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
9807                    long threadId, int start, int end) throws SystemException {
9808                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
9809            }
9810    
9811            /**
9812             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
9813             *
9814             * <p>
9815             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9816             * </p>
9817             *
9818             * @param groupId the group ID
9819             * @param categoryId the category ID
9820             * @param threadId the thread ID
9821             * @param start the lower bound of the range of message-boards messages
9822             * @param end the upper bound of the range of message-boards messages (not inclusive)
9823             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9824             * @return the ordered range of matching message-boards messages
9825             * @throws SystemException if a system exception occurred
9826             */
9827            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
9828                    long threadId, int start, int end, OrderByComparator orderByComparator)
9829                    throws SystemException {
9830                    FinderPath finderPath = null;
9831                    Object[] finderArgs = null;
9832    
9833                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9834                                    (orderByComparator == null)) {
9835                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
9836                            finderArgs = new Object[] { groupId, categoryId, threadId };
9837                    }
9838                    else {
9839                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
9840                            finderArgs = new Object[] {
9841                                            groupId, categoryId, threadId,
9842                                            
9843                                            start, end, orderByComparator
9844                                    };
9845                    }
9846    
9847                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9848                                    finderArgs, this);
9849    
9850                    if (list == null) {
9851                            StringBundler query = null;
9852    
9853                            if (orderByComparator != null) {
9854                                    query = new StringBundler(5 +
9855                                                    (orderByComparator.getOrderByFields().length * 3));
9856                            }
9857                            else {
9858                                    query = new StringBundler(5);
9859                            }
9860    
9861                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9862    
9863                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
9864    
9865                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
9866    
9867                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
9868    
9869                            if (orderByComparator != null) {
9870                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9871                                            orderByComparator);
9872                            }
9873    
9874                            else {
9875                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9876                            }
9877    
9878                            String sql = query.toString();
9879    
9880                            Session session = null;
9881    
9882                            try {
9883                                    session = openSession();
9884    
9885                                    Query q = session.createQuery(sql);
9886    
9887                                    QueryPos qPos = QueryPos.getInstance(q);
9888    
9889                                    qPos.add(groupId);
9890    
9891                                    qPos.add(categoryId);
9892    
9893                                    qPos.add(threadId);
9894    
9895                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
9896                                                    end);
9897                            }
9898                            catch (Exception e) {
9899                                    throw processException(e);
9900                            }
9901                            finally {
9902                                    if (list == null) {
9903                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
9904                                    }
9905                                    else {
9906                                            cacheResult(list);
9907    
9908                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
9909                                    }
9910    
9911                                    closeSession(session);
9912                            }
9913                    }
9914    
9915                    return list;
9916            }
9917    
9918            /**
9919             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
9920             *
9921             * <p>
9922             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9923             * </p>
9924             *
9925             * @param groupId the group ID
9926             * @param categoryId the category ID
9927             * @param threadId the thread ID
9928             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9929             * @return the first matching message-boards message
9930             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9931             * @throws SystemException if a system exception occurred
9932             */
9933            public MBMessage findByG_C_T_First(long groupId, long categoryId,
9934                    long threadId, OrderByComparator orderByComparator)
9935                    throws NoSuchMessageException, SystemException {
9936                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
9937                                    orderByComparator);
9938    
9939                    if (list.isEmpty()) {
9940                            StringBundler msg = new StringBundler(8);
9941    
9942                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9943    
9944                            msg.append("groupId=");
9945                            msg.append(groupId);
9946    
9947                            msg.append(", categoryId=");
9948                            msg.append(categoryId);
9949    
9950                            msg.append(", threadId=");
9951                            msg.append(threadId);
9952    
9953                            msg.append(StringPool.CLOSE_CURLY_BRACE);
9954    
9955                            throw new NoSuchMessageException(msg.toString());
9956                    }
9957                    else {
9958                            return list.get(0);
9959                    }
9960            }
9961    
9962            /**
9963             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
9964             *
9965             * <p>
9966             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9967             * </p>
9968             *
9969             * @param groupId the group ID
9970             * @param categoryId the category ID
9971             * @param threadId the thread ID
9972             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9973             * @return the last matching message-boards message
9974             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9975             * @throws SystemException if a system exception occurred
9976             */
9977            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
9978                    long threadId, OrderByComparator orderByComparator)
9979                    throws NoSuchMessageException, SystemException {
9980                    int count = countByG_C_T(groupId, categoryId, threadId);
9981    
9982                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
9983                                    count - 1, count, orderByComparator);
9984    
9985                    if (list.isEmpty()) {
9986                            StringBundler msg = new StringBundler(8);
9987    
9988                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9989    
9990                            msg.append("groupId=");
9991                            msg.append(groupId);
9992    
9993                            msg.append(", categoryId=");
9994                            msg.append(categoryId);
9995    
9996                            msg.append(", threadId=");
9997                            msg.append(threadId);
9998    
9999                            msg.append(StringPool.CLOSE_CURLY_BRACE);
10000    
10001                            throw new NoSuchMessageException(msg.toString());
10002                    }
10003                    else {
10004                            return list.get(0);
10005                    }
10006            }
10007    
10008            /**
10009             * 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;.
10010             *
10011             * <p>
10012             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10013             * </p>
10014             *
10015             * @param messageId the primary key of the current message-boards message
10016             * @param groupId the group ID
10017             * @param categoryId the category ID
10018             * @param threadId the thread ID
10019             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10020             * @return the previous, current, and next message-boards message
10021             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10022             * @throws SystemException if a system exception occurred
10023             */
10024            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
10025                    long categoryId, long threadId, OrderByComparator orderByComparator)
10026                    throws NoSuchMessageException, SystemException {
10027                    MBMessage mbMessage = findByPrimaryKey(messageId);
10028    
10029                    Session session = null;
10030    
10031                    try {
10032                            session = openSession();
10033    
10034                            MBMessage[] array = new MBMessageImpl[3];
10035    
10036                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
10037                                            categoryId, threadId, orderByComparator, true);
10038    
10039                            array[1] = mbMessage;
10040    
10041                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
10042                                            categoryId, threadId, orderByComparator, false);
10043    
10044                            return array;
10045                    }
10046                    catch (Exception e) {
10047                            throw processException(e);
10048                    }
10049                    finally {
10050                            closeSession(session);
10051                    }
10052            }
10053    
10054            protected MBMessage getByG_C_T_PrevAndNext(Session session,
10055                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
10056                    OrderByComparator orderByComparator, boolean previous) {
10057                    StringBundler query = null;
10058    
10059                    if (orderByComparator != null) {
10060                            query = new StringBundler(6 +
10061                                            (orderByComparator.getOrderByFields().length * 6));
10062                    }
10063                    else {
10064                            query = new StringBundler(3);
10065                    }
10066    
10067                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10068    
10069                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10070    
10071                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10072    
10073                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10074    
10075                    if (orderByComparator != null) {
10076                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10077    
10078                            if (orderByConditionFields.length > 0) {
10079                                    query.append(WHERE_AND);
10080                            }
10081    
10082                            for (int i = 0; i < orderByConditionFields.length; i++) {
10083                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10084                                    query.append(orderByConditionFields[i]);
10085    
10086                                    if ((i + 1) < orderByConditionFields.length) {
10087                                            if (orderByComparator.isAscending() ^ previous) {
10088                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10089                                            }
10090                                            else {
10091                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10092                                            }
10093                                    }
10094                                    else {
10095                                            if (orderByComparator.isAscending() ^ previous) {
10096                                                    query.append(WHERE_GREATER_THAN);
10097                                            }
10098                                            else {
10099                                                    query.append(WHERE_LESSER_THAN);
10100                                            }
10101                                    }
10102                            }
10103    
10104                            query.append(ORDER_BY_CLAUSE);
10105    
10106                            String[] orderByFields = orderByComparator.getOrderByFields();
10107    
10108                            for (int i = 0; i < orderByFields.length; i++) {
10109                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10110                                    query.append(orderByFields[i]);
10111    
10112                                    if ((i + 1) < orderByFields.length) {
10113                                            if (orderByComparator.isAscending() ^ previous) {
10114                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10115                                            }
10116                                            else {
10117                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10118                                            }
10119                                    }
10120                                    else {
10121                                            if (orderByComparator.isAscending() ^ previous) {
10122                                                    query.append(ORDER_BY_ASC);
10123                                            }
10124                                            else {
10125                                                    query.append(ORDER_BY_DESC);
10126                                            }
10127                                    }
10128                            }
10129                    }
10130    
10131                    else {
10132                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10133                    }
10134    
10135                    String sql = query.toString();
10136    
10137                    Query q = session.createQuery(sql);
10138    
10139                    q.setFirstResult(0);
10140                    q.setMaxResults(2);
10141    
10142                    QueryPos qPos = QueryPos.getInstance(q);
10143    
10144                    qPos.add(groupId);
10145    
10146                    qPos.add(categoryId);
10147    
10148                    qPos.add(threadId);
10149    
10150                    if (orderByComparator != null) {
10151                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10152    
10153                            for (Object value : values) {
10154                                    qPos.add(value);
10155                            }
10156                    }
10157    
10158                    List<MBMessage> list = q.list();
10159    
10160                    if (list.size() == 2) {
10161                            return list.get(1);
10162                    }
10163                    else {
10164                            return null;
10165                    }
10166            }
10167    
10168            /**
10169             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10170             *
10171             * @param groupId the group ID
10172             * @param categoryId the category ID
10173             * @param threadId the thread ID
10174             * @return the matching message-boards messages that the user has permission to view
10175             * @throws SystemException if a system exception occurred
10176             */
10177            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
10178                    long threadId) throws SystemException {
10179                    return filterFindByG_C_T(groupId, categoryId, threadId,
10180                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10181            }
10182    
10183            /**
10184             * 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;.
10185             *
10186             * <p>
10187             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10188             * </p>
10189             *
10190             * @param groupId the group ID
10191             * @param categoryId the category ID
10192             * @param threadId the thread ID
10193             * @param start the lower bound of the range of message-boards messages
10194             * @param end the upper bound of the range of message-boards messages (not inclusive)
10195             * @return the range of matching message-boards messages that the user has permission to view
10196             * @throws SystemException if a system exception occurred
10197             */
10198            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
10199                    long threadId, int start, int end) throws SystemException {
10200                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
10201            }
10202    
10203            /**
10204             * 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;.
10205             *
10206             * <p>
10207             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10208             * </p>
10209             *
10210             * @param groupId the group ID
10211             * @param categoryId the category ID
10212             * @param threadId the thread ID
10213             * @param start the lower bound of the range of message-boards messages
10214             * @param end the upper bound of the range of message-boards messages (not inclusive)
10215             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10216             * @return the ordered range of matching message-boards messages that the user has permission to view
10217             * @throws SystemException if a system exception occurred
10218             */
10219            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
10220                    long threadId, int start, int end, OrderByComparator orderByComparator)
10221                    throws SystemException {
10222                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10223                            return findByG_C_T(groupId, categoryId, threadId, start, end,
10224                                    orderByComparator);
10225                    }
10226    
10227                    StringBundler query = null;
10228    
10229                    if (orderByComparator != null) {
10230                            query = new StringBundler(5 +
10231                                            (orderByComparator.getOrderByFields().length * 3));
10232                    }
10233                    else {
10234                            query = new StringBundler(5);
10235                    }
10236    
10237                    if (getDB().isSupportsInlineDistinct()) {
10238                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
10239                    }
10240                    else {
10241                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
10242                    }
10243    
10244                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10245    
10246                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10247    
10248                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10249    
10250                    if (!getDB().isSupportsInlineDistinct()) {
10251                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
10252                    }
10253    
10254                    if (orderByComparator != null) {
10255                            if (getDB().isSupportsInlineDistinct()) {
10256                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10257                                            orderByComparator);
10258                            }
10259                            else {
10260                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10261                                            orderByComparator);
10262                            }
10263                    }
10264    
10265                    else {
10266                            if (getDB().isSupportsInlineDistinct()) {
10267                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10268                            }
10269                            else {
10270                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
10271                            }
10272                    }
10273    
10274                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10275                                    MBMessage.class.getName(),
10276                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10277    
10278                    Session session = null;
10279    
10280                    try {
10281                            session = openSession();
10282    
10283                            SQLQuery q = session.createSQLQuery(sql);
10284    
10285                            if (getDB().isSupportsInlineDistinct()) {
10286                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
10287                            }
10288                            else {
10289                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
10290                            }
10291    
10292                            QueryPos qPos = QueryPos.getInstance(q);
10293    
10294                            qPos.add(groupId);
10295    
10296                            qPos.add(categoryId);
10297    
10298                            qPos.add(threadId);
10299    
10300                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
10301                    }
10302                    catch (Exception e) {
10303                            throw processException(e);
10304                    }
10305                    finally {
10306                            closeSession(session);
10307                    }
10308            }
10309    
10310            /**
10311             * 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;.
10312             *
10313             * @param messageId the primary key of the current message-boards message
10314             * @param groupId the group ID
10315             * @param categoryId the category ID
10316             * @param threadId the thread ID
10317             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10318             * @return the previous, current, and next message-boards message
10319             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10320             * @throws SystemException if a system exception occurred
10321             */
10322            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
10323                    long groupId, long categoryId, long threadId,
10324                    OrderByComparator orderByComparator)
10325                    throws NoSuchMessageException, SystemException {
10326                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10327                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
10328                                    threadId, orderByComparator);
10329                    }
10330    
10331                    MBMessage mbMessage = findByPrimaryKey(messageId);
10332    
10333                    Session session = null;
10334    
10335                    try {
10336                            session = openSession();
10337    
10338                            MBMessage[] array = new MBMessageImpl[3];
10339    
10340                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
10341                                            groupId, categoryId, threadId, orderByComparator, true);
10342    
10343                            array[1] = mbMessage;
10344    
10345                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
10346                                            groupId, categoryId, threadId, orderByComparator, false);
10347    
10348                            return array;
10349                    }
10350                    catch (Exception e) {
10351                            throw processException(e);
10352                    }
10353                    finally {
10354                            closeSession(session);
10355                    }
10356            }
10357    
10358            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
10359                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
10360                    OrderByComparator orderByComparator, boolean previous) {
10361                    StringBundler query = null;
10362    
10363                    if (orderByComparator != null) {
10364                            query = new StringBundler(6 +
10365                                            (orderByComparator.getOrderByFields().length * 6));
10366                    }
10367                    else {
10368                            query = new StringBundler(3);
10369                    }
10370    
10371                    if (getDB().isSupportsInlineDistinct()) {
10372                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
10373                    }
10374                    else {
10375                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
10376                    }
10377    
10378                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10379    
10380                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10381    
10382                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10383    
10384                    if (!getDB().isSupportsInlineDistinct()) {
10385                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
10386                    }
10387    
10388                    if (orderByComparator != null) {
10389                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10390    
10391                            if (orderByConditionFields.length > 0) {
10392                                    query.append(WHERE_AND);
10393                            }
10394    
10395                            for (int i = 0; i < orderByConditionFields.length; i++) {
10396                                    if (getDB().isSupportsInlineDistinct()) {
10397                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10398                                    }
10399                                    else {
10400                                            query.append(_ORDER_BY_ENTITY_TABLE);
10401                                    }
10402    
10403                                    query.append(orderByConditionFields[i]);
10404    
10405                                    if ((i + 1) < orderByConditionFields.length) {
10406                                            if (orderByComparator.isAscending() ^ previous) {
10407                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10408                                            }
10409                                            else {
10410                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10411                                            }
10412                                    }
10413                                    else {
10414                                            if (orderByComparator.isAscending() ^ previous) {
10415                                                    query.append(WHERE_GREATER_THAN);
10416                                            }
10417                                            else {
10418                                                    query.append(WHERE_LESSER_THAN);
10419                                            }
10420                                    }
10421                            }
10422    
10423                            query.append(ORDER_BY_CLAUSE);
10424    
10425                            String[] orderByFields = orderByComparator.getOrderByFields();
10426    
10427                            for (int i = 0; i < orderByFields.length; i++) {
10428                                    if (getDB().isSupportsInlineDistinct()) {
10429                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10430                                    }
10431                                    else {
10432                                            query.append(_ORDER_BY_ENTITY_TABLE);
10433                                    }
10434    
10435                                    query.append(orderByFields[i]);
10436    
10437                                    if ((i + 1) < orderByFields.length) {
10438                                            if (orderByComparator.isAscending() ^ previous) {
10439                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10440                                            }
10441                                            else {
10442                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10443                                            }
10444                                    }
10445                                    else {
10446                                            if (orderByComparator.isAscending() ^ previous) {
10447                                                    query.append(ORDER_BY_ASC);
10448                                            }
10449                                            else {
10450                                                    query.append(ORDER_BY_DESC);
10451                                            }
10452                                    }
10453                            }
10454                    }
10455    
10456                    else {
10457                            if (getDB().isSupportsInlineDistinct()) {
10458                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10459                            }
10460                            else {
10461                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
10462                            }
10463                    }
10464    
10465                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10466                                    MBMessage.class.getName(),
10467                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10468    
10469                    SQLQuery q = session.createSQLQuery(sql);
10470    
10471                    q.setFirstResult(0);
10472                    q.setMaxResults(2);
10473    
10474                    if (getDB().isSupportsInlineDistinct()) {
10475                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
10476                    }
10477                    else {
10478                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
10479                    }
10480    
10481                    QueryPos qPos = QueryPos.getInstance(q);
10482    
10483                    qPos.add(groupId);
10484    
10485                    qPos.add(categoryId);
10486    
10487                    qPos.add(threadId);
10488    
10489                    if (orderByComparator != null) {
10490                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10491    
10492                            for (Object value : values) {
10493                                    qPos.add(value);
10494                            }
10495                    }
10496    
10497                    List<MBMessage> list = q.list();
10498    
10499                    if (list.size() == 2) {
10500                            return list.get(1);
10501                    }
10502                    else {
10503                            return null;
10504                    }
10505            }
10506    
10507            /**
10508             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
10509             *
10510             * @param groupId the group ID
10511             * @param categoryId the category ID
10512             * @param status the status
10513             * @return the matching message-boards messages
10514             * @throws SystemException if a system exception occurred
10515             */
10516            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status)
10517                    throws SystemException {
10518                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
10519                            QueryUtil.ALL_POS, null);
10520            }
10521    
10522            /**
10523             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
10524             *
10525             * <p>
10526             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10527             * </p>
10528             *
10529             * @param groupId the group ID
10530             * @param categoryId the category ID
10531             * @param status the status
10532             * @param start the lower bound of the range of message-boards messages
10533             * @param end the upper bound of the range of message-boards messages (not inclusive)
10534             * @return the range of matching message-boards messages
10535             * @throws SystemException if a system exception occurred
10536             */
10537            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
10538                    int status, int start, int end) throws SystemException {
10539                    return findByG_C_S(groupId, categoryId, status, start, end, null);
10540            }
10541    
10542            /**
10543             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
10544             *
10545             * <p>
10546             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10547             * </p>
10548             *
10549             * @param groupId the group ID
10550             * @param categoryId the category ID
10551             * @param status the status
10552             * @param start the lower bound of the range of message-boards messages
10553             * @param end the upper bound of the range of message-boards messages (not inclusive)
10554             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10555             * @return the ordered range of matching message-boards messages
10556             * @throws SystemException if a system exception occurred
10557             */
10558            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
10559                    int status, int start, int end, OrderByComparator orderByComparator)
10560                    throws SystemException {
10561                    FinderPath finderPath = null;
10562                    Object[] finderArgs = null;
10563    
10564                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10565                                    (orderByComparator == null)) {
10566                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
10567                            finderArgs = new Object[] { groupId, categoryId, status };
10568                    }
10569                    else {
10570                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
10571                            finderArgs = new Object[] {
10572                                            groupId, categoryId, status,
10573                                            
10574                                            start, end, orderByComparator
10575                                    };
10576                    }
10577    
10578                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10579                                    finderArgs, this);
10580    
10581                    if (list == null) {
10582                            StringBundler query = null;
10583    
10584                            if (orderByComparator != null) {
10585                                    query = new StringBundler(5 +
10586                                                    (orderByComparator.getOrderByFields().length * 3));
10587                            }
10588                            else {
10589                                    query = new StringBundler(5);
10590                            }
10591    
10592                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10593    
10594                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
10595    
10596                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
10597    
10598                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
10599    
10600                            if (orderByComparator != null) {
10601                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10602                                            orderByComparator);
10603                            }
10604    
10605                            else {
10606                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10607                            }
10608    
10609                            String sql = query.toString();
10610    
10611                            Session session = null;
10612    
10613                            try {
10614                                    session = openSession();
10615    
10616                                    Query q = session.createQuery(sql);
10617    
10618                                    QueryPos qPos = QueryPos.getInstance(q);
10619    
10620                                    qPos.add(groupId);
10621    
10622                                    qPos.add(categoryId);
10623    
10624                                    qPos.add(status);
10625    
10626                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
10627                                                    end);
10628                            }
10629                            catch (Exception e) {
10630                                    throw processException(e);
10631                            }
10632                            finally {
10633                                    if (list == null) {
10634                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
10635                                    }
10636                                    else {
10637                                            cacheResult(list);
10638    
10639                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
10640                                    }
10641    
10642                                    closeSession(session);
10643                            }
10644                    }
10645    
10646                    return list;
10647            }
10648    
10649            /**
10650             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
10651             *
10652             * <p>
10653             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10654             * </p>
10655             *
10656             * @param groupId the group ID
10657             * @param categoryId the category ID
10658             * @param status the status
10659             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10660             * @return the first matching message-boards message
10661             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10662             * @throws SystemException if a system exception occurred
10663             */
10664            public MBMessage findByG_C_S_First(long groupId, long categoryId,
10665                    int status, OrderByComparator orderByComparator)
10666                    throws NoSuchMessageException, SystemException {
10667                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
10668                                    orderByComparator);
10669    
10670                    if (list.isEmpty()) {
10671                            StringBundler msg = new StringBundler(8);
10672    
10673                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10674    
10675                            msg.append("groupId=");
10676                            msg.append(groupId);
10677    
10678                            msg.append(", categoryId=");
10679                            msg.append(categoryId);
10680    
10681                            msg.append(", status=");
10682                            msg.append(status);
10683    
10684                            msg.append(StringPool.CLOSE_CURLY_BRACE);
10685    
10686                            throw new NoSuchMessageException(msg.toString());
10687                    }
10688                    else {
10689                            return list.get(0);
10690                    }
10691            }
10692    
10693            /**
10694             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
10695             *
10696             * <p>
10697             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10698             * </p>
10699             *
10700             * @param groupId the group ID
10701             * @param categoryId the category ID
10702             * @param status the status
10703             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10704             * @return the last matching message-boards message
10705             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10706             * @throws SystemException if a system exception occurred
10707             */
10708            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
10709                    int status, OrderByComparator orderByComparator)
10710                    throws NoSuchMessageException, SystemException {
10711                    int count = countByG_C_S(groupId, categoryId, status);
10712    
10713                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
10714                                    count - 1, count, orderByComparator);
10715    
10716                    if (list.isEmpty()) {
10717                            StringBundler msg = new StringBundler(8);
10718    
10719                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10720    
10721                            msg.append("groupId=");
10722                            msg.append(groupId);
10723    
10724                            msg.append(", categoryId=");
10725                            msg.append(categoryId);
10726    
10727                            msg.append(", status=");
10728                            msg.append(status);
10729    
10730                            msg.append(StringPool.CLOSE_CURLY_BRACE);
10731    
10732                            throw new NoSuchMessageException(msg.toString());
10733                    }
10734                    else {
10735                            return list.get(0);
10736                    }
10737            }
10738    
10739            /**
10740             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and 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 messageId the primary key of the current message-boards message
10747             * @param groupId the group ID
10748             * @param categoryId the category ID
10749             * @param status the status
10750             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10751             * @return the previous, current, and next message-boards message
10752             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10753             * @throws SystemException if a system exception occurred
10754             */
10755            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
10756                    long categoryId, int status, OrderByComparator orderByComparator)
10757                    throws NoSuchMessageException, SystemException {
10758                    MBMessage mbMessage = findByPrimaryKey(messageId);
10759    
10760                    Session session = null;
10761    
10762                    try {
10763                            session = openSession();
10764    
10765                            MBMessage[] array = new MBMessageImpl[3];
10766    
10767                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
10768                                            categoryId, status, orderByComparator, true);
10769    
10770                            array[1] = mbMessage;
10771    
10772                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
10773                                            categoryId, status, orderByComparator, false);
10774    
10775                            return array;
10776                    }
10777                    catch (Exception e) {
10778                            throw processException(e);
10779                    }
10780                    finally {
10781                            closeSession(session);
10782                    }
10783            }
10784    
10785            protected MBMessage getByG_C_S_PrevAndNext(Session session,
10786                    MBMessage mbMessage, long groupId, long categoryId, int status,
10787                    OrderByComparator orderByComparator, boolean previous) {
10788                    StringBundler query = null;
10789    
10790                    if (orderByComparator != null) {
10791                            query = new StringBundler(6 +
10792                                            (orderByComparator.getOrderByFields().length * 6));
10793                    }
10794                    else {
10795                            query = new StringBundler(3);
10796                    }
10797    
10798                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10799    
10800                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
10801    
10802                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
10803    
10804                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
10805    
10806                    if (orderByComparator != null) {
10807                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10808    
10809                            if (orderByConditionFields.length > 0) {
10810                                    query.append(WHERE_AND);
10811                            }
10812    
10813                            for (int i = 0; i < orderByConditionFields.length; i++) {
10814                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10815                                    query.append(orderByConditionFields[i]);
10816    
10817                                    if ((i + 1) < orderByConditionFields.length) {
10818                                            if (orderByComparator.isAscending() ^ previous) {
10819                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10820                                            }
10821                                            else {
10822                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10823                                            }
10824                                    }
10825                                    else {
10826                                            if (orderByComparator.isAscending() ^ previous) {
10827                                                    query.append(WHERE_GREATER_THAN);
10828                                            }
10829                                            else {
10830                                                    query.append(WHERE_LESSER_THAN);
10831                                            }
10832                                    }
10833                            }
10834    
10835                            query.append(ORDER_BY_CLAUSE);
10836    
10837                            String[] orderByFields = orderByComparator.getOrderByFields();
10838    
10839                            for (int i = 0; i < orderByFields.length; i++) {
10840                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10841                                    query.append(orderByFields[i]);
10842    
10843                                    if ((i + 1) < orderByFields.length) {
10844                                            if (orderByComparator.isAscending() ^ previous) {
10845                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10846                                            }
10847                                            else {
10848                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10849                                            }
10850                                    }
10851                                    else {
10852                                            if (orderByComparator.isAscending() ^ previous) {
10853                                                    query.append(ORDER_BY_ASC);
10854                                            }
10855                                            else {
10856                                                    query.append(ORDER_BY_DESC);
10857                                            }
10858                                    }
10859                            }
10860                    }
10861    
10862                    else {
10863                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10864                    }
10865    
10866                    String sql = query.toString();
10867    
10868                    Query q = session.createQuery(sql);
10869    
10870                    q.setFirstResult(0);
10871                    q.setMaxResults(2);
10872    
10873                    QueryPos qPos = QueryPos.getInstance(q);
10874    
10875                    qPos.add(groupId);
10876    
10877                    qPos.add(categoryId);
10878    
10879                    qPos.add(status);
10880    
10881                    if (orderByComparator != null) {
10882                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10883    
10884                            for (Object value : values) {
10885                                    qPos.add(value);
10886                            }
10887                    }
10888    
10889                    List<MBMessage> list = q.list();
10890    
10891                    if (list.size() == 2) {
10892                            return list.get(1);
10893                    }
10894                    else {
10895                            return null;
10896                    }
10897            }
10898    
10899            /**
10900             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
10901             *
10902             * @param groupId the group ID
10903             * @param categoryId the category ID
10904             * @param status the status
10905             * @return the matching message-boards messages that the user has permission to view
10906             * @throws SystemException if a system exception occurred
10907             */
10908            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
10909                    int status) throws SystemException {
10910                    return filterFindByG_C_S(groupId, categoryId, status,
10911                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10912            }
10913    
10914            /**
10915             * 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;.
10916             *
10917             * <p>
10918             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10919             * </p>
10920             *
10921             * @param groupId the group ID
10922             * @param categoryId the category ID
10923             * @param status the status
10924             * @param start the lower bound of the range of message-boards messages
10925             * @param end the upper bound of the range of message-boards messages (not inclusive)
10926             * @return the range of matching message-boards messages that the user has permission to view
10927             * @throws SystemException if a system exception occurred
10928             */
10929            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
10930                    int status, int start, int end) throws SystemException {
10931                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
10932            }
10933    
10934            /**
10935             * 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;.
10936             *
10937             * <p>
10938             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10939             * </p>
10940             *
10941             * @param groupId the group ID
10942             * @param categoryId the category ID
10943             * @param status the status
10944             * @param start the lower bound of the range of message-boards messages
10945             * @param end the upper bound of the range of message-boards messages (not inclusive)
10946             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10947             * @return the ordered range of matching message-boards messages that the user has permission to view
10948             * @throws SystemException if a system exception occurred
10949             */
10950            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
10951                    int status, int start, int end, OrderByComparator orderByComparator)
10952                    throws SystemException {
10953                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10954                            return findByG_C_S(groupId, categoryId, status, start, end,
10955                                    orderByComparator);
10956                    }
10957    
10958                    StringBundler query = null;
10959    
10960                    if (orderByComparator != null) {
10961                            query = new StringBundler(5 +
10962                                            (orderByComparator.getOrderByFields().length * 3));
10963                    }
10964                    else {
10965                            query = new StringBundler(5);
10966                    }
10967    
10968                    if (getDB().isSupportsInlineDistinct()) {
10969                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
10970                    }
10971                    else {
10972                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
10973                    }
10974    
10975                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
10976    
10977                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
10978    
10979                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
10980    
10981                    if (!getDB().isSupportsInlineDistinct()) {
10982                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
10983                    }
10984    
10985                    if (orderByComparator != null) {
10986                            if (getDB().isSupportsInlineDistinct()) {
10987                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10988                                            orderByComparator);
10989                            }
10990                            else {
10991                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10992                                            orderByComparator);
10993                            }
10994                    }
10995    
10996                    else {
10997                            if (getDB().isSupportsInlineDistinct()) {
10998                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10999                            }
11000                            else {
11001                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11002                            }
11003                    }
11004    
11005                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11006                                    MBMessage.class.getName(),
11007                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11008    
11009                    Session session = null;
11010    
11011                    try {
11012                            session = openSession();
11013    
11014                            SQLQuery q = session.createSQLQuery(sql);
11015    
11016                            if (getDB().isSupportsInlineDistinct()) {
11017                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11018                            }
11019                            else {
11020                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11021                            }
11022    
11023                            QueryPos qPos = QueryPos.getInstance(q);
11024    
11025                            qPos.add(groupId);
11026    
11027                            qPos.add(categoryId);
11028    
11029                            qPos.add(status);
11030    
11031                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11032                    }
11033                    catch (Exception e) {
11034                            throw processException(e);
11035                    }
11036                    finally {
11037                            closeSession(session);
11038                    }
11039            }
11040    
11041            /**
11042             * 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;.
11043             *
11044             * @param messageId the primary key of the current message-boards message
11045             * @param groupId the group ID
11046             * @param categoryId the category ID
11047             * @param status the status
11048             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11049             * @return the previous, current, and next message-boards message
11050             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11051             * @throws SystemException if a system exception occurred
11052             */
11053            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
11054                    long groupId, long categoryId, int status,
11055                    OrderByComparator orderByComparator)
11056                    throws NoSuchMessageException, SystemException {
11057                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11058                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
11059                                    status, orderByComparator);
11060                    }
11061    
11062                    MBMessage mbMessage = findByPrimaryKey(messageId);
11063    
11064                    Session session = null;
11065    
11066                    try {
11067                            session = openSession();
11068    
11069                            MBMessage[] array = new MBMessageImpl[3];
11070    
11071                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
11072                                            groupId, categoryId, status, orderByComparator, true);
11073    
11074                            array[1] = mbMessage;
11075    
11076                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
11077                                            groupId, categoryId, status, orderByComparator, false);
11078    
11079                            return array;
11080                    }
11081                    catch (Exception e) {
11082                            throw processException(e);
11083                    }
11084                    finally {
11085                            closeSession(session);
11086                    }
11087            }
11088    
11089            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
11090                    MBMessage mbMessage, long groupId, long categoryId, int status,
11091                    OrderByComparator orderByComparator, boolean previous) {
11092                    StringBundler query = null;
11093    
11094                    if (orderByComparator != null) {
11095                            query = new StringBundler(6 +
11096                                            (orderByComparator.getOrderByFields().length * 6));
11097                    }
11098                    else {
11099                            query = new StringBundler(3);
11100                    }
11101    
11102                    if (getDB().isSupportsInlineDistinct()) {
11103                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11104                    }
11105                    else {
11106                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11107                    }
11108    
11109                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
11110    
11111                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
11112    
11113                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
11114    
11115                    if (!getDB().isSupportsInlineDistinct()) {
11116                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11117                    }
11118    
11119                    if (orderByComparator != null) {
11120                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11121    
11122                            if (orderByConditionFields.length > 0) {
11123                                    query.append(WHERE_AND);
11124                            }
11125    
11126                            for (int i = 0; i < orderByConditionFields.length; i++) {
11127                                    if (getDB().isSupportsInlineDistinct()) {
11128                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11129                                    }
11130                                    else {
11131                                            query.append(_ORDER_BY_ENTITY_TABLE);
11132                                    }
11133    
11134                                    query.append(orderByConditionFields[i]);
11135    
11136                                    if ((i + 1) < orderByConditionFields.length) {
11137                                            if (orderByComparator.isAscending() ^ previous) {
11138                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11139                                            }
11140                                            else {
11141                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11142                                            }
11143                                    }
11144                                    else {
11145                                            if (orderByComparator.isAscending() ^ previous) {
11146                                                    query.append(WHERE_GREATER_THAN);
11147                                            }
11148                                            else {
11149                                                    query.append(WHERE_LESSER_THAN);
11150                                            }
11151                                    }
11152                            }
11153    
11154                            query.append(ORDER_BY_CLAUSE);
11155    
11156                            String[] orderByFields = orderByComparator.getOrderByFields();
11157    
11158                            for (int i = 0; i < orderByFields.length; i++) {
11159                                    if (getDB().isSupportsInlineDistinct()) {
11160                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11161                                    }
11162                                    else {
11163                                            query.append(_ORDER_BY_ENTITY_TABLE);
11164                                    }
11165    
11166                                    query.append(orderByFields[i]);
11167    
11168                                    if ((i + 1) < orderByFields.length) {
11169                                            if (orderByComparator.isAscending() ^ previous) {
11170                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11171                                            }
11172                                            else {
11173                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11174                                            }
11175                                    }
11176                                    else {
11177                                            if (orderByComparator.isAscending() ^ previous) {
11178                                                    query.append(ORDER_BY_ASC);
11179                                            }
11180                                            else {
11181                                                    query.append(ORDER_BY_DESC);
11182                                            }
11183                                    }
11184                            }
11185                    }
11186    
11187                    else {
11188                            if (getDB().isSupportsInlineDistinct()) {
11189                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11190                            }
11191                            else {
11192                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11193                            }
11194                    }
11195    
11196                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11197                                    MBMessage.class.getName(),
11198                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11199    
11200                    SQLQuery q = session.createSQLQuery(sql);
11201    
11202                    q.setFirstResult(0);
11203                    q.setMaxResults(2);
11204    
11205                    if (getDB().isSupportsInlineDistinct()) {
11206                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11207                    }
11208                    else {
11209                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11210                    }
11211    
11212                    QueryPos qPos = QueryPos.getInstance(q);
11213    
11214                    qPos.add(groupId);
11215    
11216                    qPos.add(categoryId);
11217    
11218                    qPos.add(status);
11219    
11220                    if (orderByComparator != null) {
11221                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11222    
11223                            for (Object value : values) {
11224                                    qPos.add(value);
11225                            }
11226                    }
11227    
11228                    List<MBMessage> list = q.list();
11229    
11230                    if (list.size() == 2) {
11231                            return list.get(1);
11232                    }
11233                    else {
11234                            return null;
11235                    }
11236            }
11237    
11238            /**
11239             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
11240             *
11241             * @param userId the user ID
11242             * @param classNameId the class name ID
11243             * @param classPK the class p k
11244             * @return the matching message-boards messages
11245             * @throws SystemException if a system exception occurred
11246             */
11247            public List<MBMessage> findByU_C_C(long userId, long classNameId,
11248                    long classPK) throws SystemException {
11249                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
11250                            QueryUtil.ALL_POS, null);
11251            }
11252    
11253            /**
11254             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
11255             *
11256             * <p>
11257             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11258             * </p>
11259             *
11260             * @param userId the user ID
11261             * @param classNameId the class name ID
11262             * @param classPK the class p k
11263             * @param start the lower bound of the range of message-boards messages
11264             * @param end the upper bound of the range of message-boards messages (not inclusive)
11265             * @return the range of matching message-boards messages
11266             * @throws SystemException if a system exception occurred
11267             */
11268            public List<MBMessage> findByU_C_C(long userId, long classNameId,
11269                    long classPK, int start, int end) throws SystemException {
11270                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
11271            }
11272    
11273            /**
11274             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
11275             *
11276             * <p>
11277             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11278             * </p>
11279             *
11280             * @param userId the user ID
11281             * @param classNameId the class name ID
11282             * @param classPK the class p k
11283             * @param start the lower bound of the range of message-boards messages
11284             * @param end the upper bound of the range of message-boards messages (not inclusive)
11285             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11286             * @return the ordered range of matching message-boards messages
11287             * @throws SystemException if a system exception occurred
11288             */
11289            public List<MBMessage> findByU_C_C(long userId, long classNameId,
11290                    long classPK, int start, int end, OrderByComparator orderByComparator)
11291                    throws SystemException {
11292                    FinderPath finderPath = null;
11293                    Object[] finderArgs = null;
11294    
11295                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11296                                    (orderByComparator == null)) {
11297                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
11298                            finderArgs = new Object[] { userId, classNameId, classPK };
11299                    }
11300                    else {
11301                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
11302                            finderArgs = new Object[] {
11303                                            userId, classNameId, classPK,
11304                                            
11305                                            start, end, orderByComparator
11306                                    };
11307                    }
11308    
11309                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
11310                                    finderArgs, this);
11311    
11312                    if (list == null) {
11313                            StringBundler query = null;
11314    
11315                            if (orderByComparator != null) {
11316                                    query = new StringBundler(5 +
11317                                                    (orderByComparator.getOrderByFields().length * 3));
11318                            }
11319                            else {
11320                                    query = new StringBundler(5);
11321                            }
11322    
11323                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11324    
11325                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
11326    
11327                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
11328    
11329                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
11330    
11331                            if (orderByComparator != null) {
11332                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11333                                            orderByComparator);
11334                            }
11335    
11336                            else {
11337                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11338                            }
11339    
11340                            String sql = query.toString();
11341    
11342                            Session session = null;
11343    
11344                            try {
11345                                    session = openSession();
11346    
11347                                    Query q = session.createQuery(sql);
11348    
11349                                    QueryPos qPos = QueryPos.getInstance(q);
11350    
11351                                    qPos.add(userId);
11352    
11353                                    qPos.add(classNameId);
11354    
11355                                    qPos.add(classPK);
11356    
11357                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
11358                                                    end);
11359                            }
11360                            catch (Exception e) {
11361                                    throw processException(e);
11362                            }
11363                            finally {
11364                                    if (list == null) {
11365                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
11366                                    }
11367                                    else {
11368                                            cacheResult(list);
11369    
11370                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
11371                                    }
11372    
11373                                    closeSession(session);
11374                            }
11375                    }
11376    
11377                    return list;
11378            }
11379    
11380            /**
11381             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
11382             *
11383             * <p>
11384             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11385             * </p>
11386             *
11387             * @param userId the user ID
11388             * @param classNameId the class name ID
11389             * @param classPK the class p k
11390             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11391             * @return the first matching message-boards message
11392             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11393             * @throws SystemException if a system exception occurred
11394             */
11395            public MBMessage findByU_C_C_First(long userId, long classNameId,
11396                    long classPK, OrderByComparator orderByComparator)
11397                    throws NoSuchMessageException, SystemException {
11398                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
11399                                    orderByComparator);
11400    
11401                    if (list.isEmpty()) {
11402                            StringBundler msg = new StringBundler(8);
11403    
11404                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11405    
11406                            msg.append("userId=");
11407                            msg.append(userId);
11408    
11409                            msg.append(", classNameId=");
11410                            msg.append(classNameId);
11411    
11412                            msg.append(", classPK=");
11413                            msg.append(classPK);
11414    
11415                            msg.append(StringPool.CLOSE_CURLY_BRACE);
11416    
11417                            throw new NoSuchMessageException(msg.toString());
11418                    }
11419                    else {
11420                            return list.get(0);
11421                    }
11422            }
11423    
11424            /**
11425             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
11426             *
11427             * <p>
11428             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11429             * </p>
11430             *
11431             * @param userId the user ID
11432             * @param classNameId the class name ID
11433             * @param classPK the class p k
11434             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11435             * @return the last matching message-boards message
11436             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11437             * @throws SystemException if a system exception occurred
11438             */
11439            public MBMessage findByU_C_C_Last(long userId, long classNameId,
11440                    long classPK, OrderByComparator orderByComparator)
11441                    throws NoSuchMessageException, SystemException {
11442                    int count = countByU_C_C(userId, classNameId, classPK);
11443    
11444                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
11445                                    count - 1, count, orderByComparator);
11446    
11447                    if (list.isEmpty()) {
11448                            StringBundler msg = new StringBundler(8);
11449    
11450                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11451    
11452                            msg.append("userId=");
11453                            msg.append(userId);
11454    
11455                            msg.append(", classNameId=");
11456                            msg.append(classNameId);
11457    
11458                            msg.append(", classPK=");
11459                            msg.append(classPK);
11460    
11461                            msg.append(StringPool.CLOSE_CURLY_BRACE);
11462    
11463                            throw new NoSuchMessageException(msg.toString());
11464                    }
11465                    else {
11466                            return list.get(0);
11467                    }
11468            }
11469    
11470            /**
11471             * 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;.
11472             *
11473             * <p>
11474             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11475             * </p>
11476             *
11477             * @param messageId the primary key of the current message-boards message
11478             * @param userId the user ID
11479             * @param classNameId the class name ID
11480             * @param classPK the class p k
11481             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11482             * @return the previous, current, and next message-boards message
11483             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11484             * @throws SystemException if a system exception occurred
11485             */
11486            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
11487                    long classNameId, long classPK, OrderByComparator orderByComparator)
11488                    throws NoSuchMessageException, SystemException {
11489                    MBMessage mbMessage = findByPrimaryKey(messageId);
11490    
11491                    Session session = null;
11492    
11493                    try {
11494                            session = openSession();
11495    
11496                            MBMessage[] array = new MBMessageImpl[3];
11497    
11498                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
11499                                            classNameId, classPK, orderByComparator, true);
11500    
11501                            array[1] = mbMessage;
11502    
11503                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
11504                                            classNameId, classPK, orderByComparator, false);
11505    
11506                            return array;
11507                    }
11508                    catch (Exception e) {
11509                            throw processException(e);
11510                    }
11511                    finally {
11512                            closeSession(session);
11513                    }
11514            }
11515    
11516            protected MBMessage getByU_C_C_PrevAndNext(Session session,
11517                    MBMessage mbMessage, long userId, long classNameId, long classPK,
11518                    OrderByComparator orderByComparator, boolean previous) {
11519                    StringBundler query = null;
11520    
11521                    if (orderByComparator != null) {
11522                            query = new StringBundler(6 +
11523                                            (orderByComparator.getOrderByFields().length * 6));
11524                    }
11525                    else {
11526                            query = new StringBundler(3);
11527                    }
11528    
11529                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11530    
11531                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
11532    
11533                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
11534    
11535                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
11536    
11537                    if (orderByComparator != null) {
11538                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11539    
11540                            if (orderByConditionFields.length > 0) {
11541                                    query.append(WHERE_AND);
11542                            }
11543    
11544                            for (int i = 0; i < orderByConditionFields.length; i++) {
11545                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11546                                    query.append(orderByConditionFields[i]);
11547    
11548                                    if ((i + 1) < orderByConditionFields.length) {
11549                                            if (orderByComparator.isAscending() ^ previous) {
11550                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11551                                            }
11552                                            else {
11553                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11554                                            }
11555                                    }
11556                                    else {
11557                                            if (orderByComparator.isAscending() ^ previous) {
11558                                                    query.append(WHERE_GREATER_THAN);
11559                                            }
11560                                            else {
11561                                                    query.append(WHERE_LESSER_THAN);
11562                                            }
11563                                    }
11564                            }
11565    
11566                            query.append(ORDER_BY_CLAUSE);
11567    
11568                            String[] orderByFields = orderByComparator.getOrderByFields();
11569    
11570                            for (int i = 0; i < orderByFields.length; i++) {
11571                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11572                                    query.append(orderByFields[i]);
11573    
11574                                    if ((i + 1) < orderByFields.length) {
11575                                            if (orderByComparator.isAscending() ^ previous) {
11576                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11577                                            }
11578                                            else {
11579                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11580                                            }
11581                                    }
11582                                    else {
11583                                            if (orderByComparator.isAscending() ^ previous) {
11584                                                    query.append(ORDER_BY_ASC);
11585                                            }
11586                                            else {
11587                                                    query.append(ORDER_BY_DESC);
11588                                            }
11589                                    }
11590                            }
11591                    }
11592    
11593                    else {
11594                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11595                    }
11596    
11597                    String sql = query.toString();
11598    
11599                    Query q = session.createQuery(sql);
11600    
11601                    q.setFirstResult(0);
11602                    q.setMaxResults(2);
11603    
11604                    QueryPos qPos = QueryPos.getInstance(q);
11605    
11606                    qPos.add(userId);
11607    
11608                    qPos.add(classNameId);
11609    
11610                    qPos.add(classPK);
11611    
11612                    if (orderByComparator != null) {
11613                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11614    
11615                            for (Object value : values) {
11616                                    qPos.add(value);
11617                            }
11618                    }
11619    
11620                    List<MBMessage> list = q.list();
11621    
11622                    if (list.size() == 2) {
11623                            return list.get(1);
11624                    }
11625                    else {
11626                            return null;
11627                    }
11628            }
11629    
11630            /**
11631             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
11632             *
11633             * @param userId the user ID
11634             * @param classNameId the class name ID
11635             * @param status the status
11636             * @return the matching message-boards messages
11637             * @throws SystemException if a system exception occurred
11638             */
11639            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status)
11640                    throws SystemException {
11641                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
11642                            QueryUtil.ALL_POS, null);
11643            }
11644    
11645            /**
11646             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
11647             *
11648             * <p>
11649             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11650             * </p>
11651             *
11652             * @param userId the user ID
11653             * @param classNameId the class name ID
11654             * @param status the status
11655             * @param start the lower bound of the range of message-boards messages
11656             * @param end the upper bound of the range of message-boards messages (not inclusive)
11657             * @return the range of matching message-boards messages
11658             * @throws SystemException if a system exception occurred
11659             */
11660            public List<MBMessage> findByU_C_S(long userId, long classNameId,
11661                    int status, int start, int end) throws SystemException {
11662                    return findByU_C_S(userId, classNameId, status, start, end, null);
11663            }
11664    
11665            /**
11666             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#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 status the status
11675             * @param start the lower bound of the range of message-boards messages
11676             * @param end the upper bound of the range of message-boards messages (not inclusive)
11677             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11678             * @return the ordered range of matching message-boards messages
11679             * @throws SystemException if a system exception occurred
11680             */
11681            public List<MBMessage> findByU_C_S(long userId, long classNameId,
11682                    int status, int start, int end, OrderByComparator orderByComparator)
11683                    throws SystemException {
11684                    FinderPath finderPath = null;
11685                    Object[] finderArgs = null;
11686    
11687                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11688                                    (orderByComparator == null)) {
11689                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
11690                            finderArgs = new Object[] { userId, classNameId, status };
11691                    }
11692                    else {
11693                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
11694                            finderArgs = new Object[] {
11695                                            userId, classNameId, status,
11696                                            
11697                                            start, end, orderByComparator
11698                                    };
11699                    }
11700    
11701                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
11702                                    finderArgs, this);
11703    
11704                    if (list == null) {
11705                            StringBundler query = null;
11706    
11707                            if (orderByComparator != null) {
11708                                    query = new StringBundler(5 +
11709                                                    (orderByComparator.getOrderByFields().length * 3));
11710                            }
11711                            else {
11712                                    query = new StringBundler(5);
11713                            }
11714    
11715                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11716    
11717                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
11718    
11719                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
11720    
11721                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
11722    
11723                            if (orderByComparator != null) {
11724                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11725                                            orderByComparator);
11726                            }
11727    
11728                            else {
11729                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11730                            }
11731    
11732                            String sql = query.toString();
11733    
11734                            Session session = null;
11735    
11736                            try {
11737                                    session = openSession();
11738    
11739                                    Query q = session.createQuery(sql);
11740    
11741                                    QueryPos qPos = QueryPos.getInstance(q);
11742    
11743                                    qPos.add(userId);
11744    
11745                                    qPos.add(classNameId);
11746    
11747                                    qPos.add(status);
11748    
11749                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
11750                                                    end);
11751                            }
11752                            catch (Exception e) {
11753                                    throw processException(e);
11754                            }
11755                            finally {
11756                                    if (list == null) {
11757                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
11758                                    }
11759                                    else {
11760                                            cacheResult(list);
11761    
11762                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
11763                                    }
11764    
11765                                    closeSession(session);
11766                            }
11767                    }
11768    
11769                    return list;
11770            }
11771    
11772            /**
11773             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
11774             *
11775             * <p>
11776             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11777             * </p>
11778             *
11779             * @param userId the user ID
11780             * @param classNameId the class name ID
11781             * @param status the status
11782             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11783             * @return the first matching message-boards message
11784             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11785             * @throws SystemException if a system exception occurred
11786             */
11787            public MBMessage findByU_C_S_First(long userId, long classNameId,
11788                    int status, OrderByComparator orderByComparator)
11789                    throws NoSuchMessageException, SystemException {
11790                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
11791                                    orderByComparator);
11792    
11793                    if (list.isEmpty()) {
11794                            StringBundler msg = new StringBundler(8);
11795    
11796                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11797    
11798                            msg.append("userId=");
11799                            msg.append(userId);
11800    
11801                            msg.append(", classNameId=");
11802                            msg.append(classNameId);
11803    
11804                            msg.append(", status=");
11805                            msg.append(status);
11806    
11807                            msg.append(StringPool.CLOSE_CURLY_BRACE);
11808    
11809                            throw new NoSuchMessageException(msg.toString());
11810                    }
11811                    else {
11812                            return list.get(0);
11813                    }
11814            }
11815    
11816            /**
11817             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
11818             *
11819             * <p>
11820             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11821             * </p>
11822             *
11823             * @param userId the user ID
11824             * @param classNameId the class name ID
11825             * @param status the status
11826             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11827             * @return the last matching message-boards message
11828             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11829             * @throws SystemException if a system exception occurred
11830             */
11831            public MBMessage findByU_C_S_Last(long userId, long classNameId,
11832                    int status, OrderByComparator orderByComparator)
11833                    throws NoSuchMessageException, SystemException {
11834                    int count = countByU_C_S(userId, classNameId, status);
11835    
11836                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
11837                                    count - 1, count, orderByComparator);
11838    
11839                    if (list.isEmpty()) {
11840                            StringBundler msg = new StringBundler(8);
11841    
11842                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11843    
11844                            msg.append("userId=");
11845                            msg.append(userId);
11846    
11847                            msg.append(", classNameId=");
11848                            msg.append(classNameId);
11849    
11850                            msg.append(", status=");
11851                            msg.append(status);
11852    
11853                            msg.append(StringPool.CLOSE_CURLY_BRACE);
11854    
11855                            throw new NoSuchMessageException(msg.toString());
11856                    }
11857                    else {
11858                            return list.get(0);
11859                    }
11860            }
11861    
11862            /**
11863             * 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;.
11864             *
11865             * <p>
11866             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11867             * </p>
11868             *
11869             * @param messageId the primary key of the current message-boards message
11870             * @param userId the user ID
11871             * @param classNameId the class name ID
11872             * @param status the status
11873             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11874             * @return the previous, current, and next message-boards message
11875             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11876             * @throws SystemException if a system exception occurred
11877             */
11878            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
11879                    long classNameId, int status, OrderByComparator orderByComparator)
11880                    throws NoSuchMessageException, SystemException {
11881                    MBMessage mbMessage = findByPrimaryKey(messageId);
11882    
11883                    Session session = null;
11884    
11885                    try {
11886                            session = openSession();
11887    
11888                            MBMessage[] array = new MBMessageImpl[3];
11889    
11890                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
11891                                            classNameId, status, orderByComparator, true);
11892    
11893                            array[1] = mbMessage;
11894    
11895                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
11896                                            classNameId, status, orderByComparator, false);
11897    
11898                            return array;
11899                    }
11900                    catch (Exception e) {
11901                            throw processException(e);
11902                    }
11903                    finally {
11904                            closeSession(session);
11905                    }
11906            }
11907    
11908            protected MBMessage getByU_C_S_PrevAndNext(Session session,
11909                    MBMessage mbMessage, long userId, long classNameId, int status,
11910                    OrderByComparator orderByComparator, boolean previous) {
11911                    StringBundler query = null;
11912    
11913                    if (orderByComparator != null) {
11914                            query = new StringBundler(6 +
11915                                            (orderByComparator.getOrderByFields().length * 6));
11916                    }
11917                    else {
11918                            query = new StringBundler(3);
11919                    }
11920    
11921                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11922    
11923                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
11924    
11925                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
11926    
11927                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
11928    
11929                    if (orderByComparator != null) {
11930                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11931    
11932                            if (orderByConditionFields.length > 0) {
11933                                    query.append(WHERE_AND);
11934                            }
11935    
11936                            for (int i = 0; i < orderByConditionFields.length; i++) {
11937                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11938                                    query.append(orderByConditionFields[i]);
11939    
11940                                    if ((i + 1) < orderByConditionFields.length) {
11941                                            if (orderByComparator.isAscending() ^ previous) {
11942                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11943                                            }
11944                                            else {
11945                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11946                                            }
11947                                    }
11948                                    else {
11949                                            if (orderByComparator.isAscending() ^ previous) {
11950                                                    query.append(WHERE_GREATER_THAN);
11951                                            }
11952                                            else {
11953                                                    query.append(WHERE_LESSER_THAN);
11954                                            }
11955                                    }
11956                            }
11957    
11958                            query.append(ORDER_BY_CLAUSE);
11959    
11960                            String[] orderByFields = orderByComparator.getOrderByFields();
11961    
11962                            for (int i = 0; i < orderByFields.length; i++) {
11963                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11964                                    query.append(orderByFields[i]);
11965    
11966                                    if ((i + 1) < orderByFields.length) {
11967                                            if (orderByComparator.isAscending() ^ previous) {
11968                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11969                                            }
11970                                            else {
11971                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11972                                            }
11973                                    }
11974                                    else {
11975                                            if (orderByComparator.isAscending() ^ previous) {
11976                                                    query.append(ORDER_BY_ASC);
11977                                            }
11978                                            else {
11979                                                    query.append(ORDER_BY_DESC);
11980                                            }
11981                                    }
11982                            }
11983                    }
11984    
11985                    else {
11986                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11987                    }
11988    
11989                    String sql = query.toString();
11990    
11991                    Query q = session.createQuery(sql);
11992    
11993                    q.setFirstResult(0);
11994                    q.setMaxResults(2);
11995    
11996                    QueryPos qPos = QueryPos.getInstance(q);
11997    
11998                    qPos.add(userId);
11999    
12000                    qPos.add(classNameId);
12001    
12002                    qPos.add(status);
12003    
12004                    if (orderByComparator != null) {
12005                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12006    
12007                            for (Object value : values) {
12008                                    qPos.add(value);
12009                            }
12010                    }
12011    
12012                    List<MBMessage> list = q.list();
12013    
12014                    if (list.size() == 2) {
12015                            return list.get(1);
12016                    }
12017                    else {
12018                            return null;
12019                    }
12020            }
12021    
12022            /**
12023             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
12024             *
12025             * <p>
12026             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12027             * </p>
12028             *
12029             * @param userId the user ID
12030             * @param classNameIds the class name IDs
12031             * @param status the status
12032             * @return the matching message-boards messages
12033             * @throws SystemException if a system exception occurred
12034             */
12035            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
12036                    int status) throws SystemException {
12037                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
12038                            QueryUtil.ALL_POS, null);
12039            }
12040    
12041            /**
12042             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
12043             *
12044             * <p>
12045             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12046             * </p>
12047             *
12048             * @param userId the user ID
12049             * @param classNameIds the class name IDs
12050             * @param status the status
12051             * @param start the lower bound of the range of message-boards messages
12052             * @param end the upper bound of the range of message-boards messages (not inclusive)
12053             * @return the range of matching message-boards messages
12054             * @throws SystemException if a system exception occurred
12055             */
12056            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
12057                    int status, int start, int end) throws SystemException {
12058                    return findByU_C_S(userId, classNameIds, status, start, end, null);
12059            }
12060    
12061            /**
12062             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
12063             *
12064             * <p>
12065             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12066             * </p>
12067             *
12068             * @param userId the user ID
12069             * @param classNameIds the class name IDs
12070             * @param status the status
12071             * @param start the lower bound of the range of message-boards messages
12072             * @param end the upper bound of the range of message-boards messages (not inclusive)
12073             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12074             * @return the ordered range of matching message-boards messages
12075             * @throws SystemException if a system exception occurred
12076             */
12077            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
12078                    int status, int start, int end, OrderByComparator orderByComparator)
12079                    throws SystemException {
12080                    FinderPath finderPath = null;
12081                    Object[] finderArgs = null;
12082    
12083                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12084                                    (orderByComparator == null)) {
12085                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
12086                            finderArgs = new Object[] {
12087                                            userId, StringUtil.merge(classNameIds), status
12088                                    };
12089                    }
12090                    else {
12091                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
12092                            finderArgs = new Object[] {
12093                                            userId, StringUtil.merge(classNameIds), status,
12094                                            
12095                                            start, end, orderByComparator
12096                                    };
12097                    }
12098    
12099                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12100                                    finderArgs, this);
12101    
12102                    if (list == null) {
12103                            StringBundler query = new StringBundler();
12104    
12105                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12106    
12107                            boolean conjunctionable = false;
12108    
12109                            if (conjunctionable) {
12110                                    query.append(WHERE_AND);
12111                            }
12112    
12113                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
12114    
12115                            conjunctionable = true;
12116    
12117                            if ((classNameIds == null) || (classNameIds.length > 0)) {
12118                                    if (conjunctionable) {
12119                                            query.append(WHERE_AND);
12120                                    }
12121    
12122                                    query.append(StringPool.OPEN_PARENTHESIS);
12123    
12124                                    for (int i = 0; i < classNameIds.length; i++) {
12125                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
12126    
12127                                            if ((i + 1) < classNameIds.length) {
12128                                                    query.append(WHERE_OR);
12129                                            }
12130                                    }
12131    
12132                                    query.append(StringPool.CLOSE_PARENTHESIS);
12133    
12134                                    conjunctionable = true;
12135                            }
12136    
12137                            if (conjunctionable) {
12138                                    query.append(WHERE_AND);
12139                            }
12140    
12141                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
12142    
12143                            conjunctionable = true;
12144    
12145                            if (orderByComparator != null) {
12146                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12147                                            orderByComparator);
12148                            }
12149    
12150                            else {
12151                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12152                            }
12153    
12154                            String sql = query.toString();
12155    
12156                            Session session = null;
12157    
12158                            try {
12159                                    session = openSession();
12160    
12161                                    Query q = session.createQuery(sql);
12162    
12163                                    QueryPos qPos = QueryPos.getInstance(q);
12164    
12165                                    qPos.add(userId);
12166    
12167                                    if (classNameIds != null) {
12168                                            qPos.add(classNameIds);
12169                                    }
12170    
12171                                    qPos.add(status);
12172    
12173                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
12174                                                    end);
12175                            }
12176                            catch (Exception e) {
12177                                    throw processException(e);
12178                            }
12179                            finally {
12180                                    if (list == null) {
12181                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
12182                                    }
12183                                    else {
12184                                            cacheResult(list);
12185    
12186                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
12187                                    }
12188    
12189                                    closeSession(session);
12190                            }
12191                    }
12192    
12193                    return list;
12194            }
12195    
12196            /**
12197             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
12198             *
12199             * @param classNameId the class name ID
12200             * @param classPK the class p k
12201             * @param status the status
12202             * @return the matching message-boards messages
12203             * @throws SystemException if a system exception occurred
12204             */
12205            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
12206                    int status) throws SystemException {
12207                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
12208                            QueryUtil.ALL_POS, null);
12209            }
12210    
12211            /**
12212             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
12213             *
12214             * <p>
12215             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12216             * </p>
12217             *
12218             * @param classNameId the class name ID
12219             * @param classPK the class p k
12220             * @param status the status
12221             * @param start the lower bound of the range of message-boards messages
12222             * @param end the upper bound of the range of message-boards messages (not inclusive)
12223             * @return the range of matching message-boards messages
12224             * @throws SystemException if a system exception occurred
12225             */
12226            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
12227                    int status, int start, int end) throws SystemException {
12228                    return findByC_C_S(classNameId, classPK, status, start, end, null);
12229            }
12230    
12231            /**
12232             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
12233             *
12234             * <p>
12235             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12236             * </p>
12237             *
12238             * @param classNameId the class name ID
12239             * @param classPK the class p k
12240             * @param status the status
12241             * @param start the lower bound of the range of message-boards messages
12242             * @param end the upper bound of the range of message-boards messages (not inclusive)
12243             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12244             * @return the ordered range of matching message-boards messages
12245             * @throws SystemException if a system exception occurred
12246             */
12247            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
12248                    int status, int start, int end, OrderByComparator orderByComparator)
12249                    throws SystemException {
12250                    FinderPath finderPath = null;
12251                    Object[] finderArgs = null;
12252    
12253                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12254                                    (orderByComparator == null)) {
12255                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
12256                            finderArgs = new Object[] { classNameId, classPK, status };
12257                    }
12258                    else {
12259                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
12260                            finderArgs = new Object[] {
12261                                            classNameId, classPK, status,
12262                                            
12263                                            start, end, orderByComparator
12264                                    };
12265                    }
12266    
12267                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12268                                    finderArgs, this);
12269    
12270                    if (list == null) {
12271                            StringBundler query = null;
12272    
12273                            if (orderByComparator != null) {
12274                                    query = new StringBundler(5 +
12275                                                    (orderByComparator.getOrderByFields().length * 3));
12276                            }
12277                            else {
12278                                    query = new StringBundler(5);
12279                            }
12280    
12281                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12282    
12283                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
12284    
12285                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
12286    
12287                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
12288    
12289                            if (orderByComparator != null) {
12290                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12291                                            orderByComparator);
12292                            }
12293    
12294                            else {
12295                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12296                            }
12297    
12298                            String sql = query.toString();
12299    
12300                            Session session = null;
12301    
12302                            try {
12303                                    session = openSession();
12304    
12305                                    Query q = session.createQuery(sql);
12306    
12307                                    QueryPos qPos = QueryPos.getInstance(q);
12308    
12309                                    qPos.add(classNameId);
12310    
12311                                    qPos.add(classPK);
12312    
12313                                    qPos.add(status);
12314    
12315                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
12316                                                    end);
12317                            }
12318                            catch (Exception e) {
12319                                    throw processException(e);
12320                            }
12321                            finally {
12322                                    if (list == null) {
12323                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
12324                                    }
12325                                    else {
12326                                            cacheResult(list);
12327    
12328                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
12329                                    }
12330    
12331                                    closeSession(session);
12332                            }
12333                    }
12334    
12335                    return list;
12336            }
12337    
12338            /**
12339             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
12340             *
12341             * <p>
12342             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12343             * </p>
12344             *
12345             * @param classNameId the class name ID
12346             * @param classPK the class p k
12347             * @param status the status
12348             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12349             * @return the first matching message-boards message
12350             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12351             * @throws SystemException if a system exception occurred
12352             */
12353            public MBMessage findByC_C_S_First(long classNameId, long classPK,
12354                    int status, OrderByComparator orderByComparator)
12355                    throws NoSuchMessageException, SystemException {
12356                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
12357                                    orderByComparator);
12358    
12359                    if (list.isEmpty()) {
12360                            StringBundler msg = new StringBundler(8);
12361    
12362                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12363    
12364                            msg.append("classNameId=");
12365                            msg.append(classNameId);
12366    
12367                            msg.append(", classPK=");
12368                            msg.append(classPK);
12369    
12370                            msg.append(", status=");
12371                            msg.append(status);
12372    
12373                            msg.append(StringPool.CLOSE_CURLY_BRACE);
12374    
12375                            throw new NoSuchMessageException(msg.toString());
12376                    }
12377                    else {
12378                            return list.get(0);
12379                    }
12380            }
12381    
12382            /**
12383             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
12384             *
12385             * <p>
12386             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12387             * </p>
12388             *
12389             * @param classNameId the class name ID
12390             * @param classPK the class p k
12391             * @param status the status
12392             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12393             * @return the last matching message-boards message
12394             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12395             * @throws SystemException if a system exception occurred
12396             */
12397            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
12398                    int status, OrderByComparator orderByComparator)
12399                    throws NoSuchMessageException, SystemException {
12400                    int count = countByC_C_S(classNameId, classPK, status);
12401    
12402                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
12403                                    count - 1, count, orderByComparator);
12404    
12405                    if (list.isEmpty()) {
12406                            StringBundler msg = new StringBundler(8);
12407    
12408                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12409    
12410                            msg.append("classNameId=");
12411                            msg.append(classNameId);
12412    
12413                            msg.append(", classPK=");
12414                            msg.append(classPK);
12415    
12416                            msg.append(", status=");
12417                            msg.append(status);
12418    
12419                            msg.append(StringPool.CLOSE_CURLY_BRACE);
12420    
12421                            throw new NoSuchMessageException(msg.toString());
12422                    }
12423                    else {
12424                            return list.get(0);
12425                    }
12426            }
12427    
12428            /**
12429             * 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;.
12430             *
12431             * <p>
12432             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12433             * </p>
12434             *
12435             * @param messageId the primary key of the current message-boards message
12436             * @param classNameId the class name ID
12437             * @param classPK the class p k
12438             * @param status the status
12439             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12440             * @return the previous, current, and next message-boards message
12441             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12442             * @throws SystemException if a system exception occurred
12443             */
12444            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
12445                    long classNameId, long classPK, int status,
12446                    OrderByComparator orderByComparator)
12447                    throws NoSuchMessageException, SystemException {
12448                    MBMessage mbMessage = findByPrimaryKey(messageId);
12449    
12450                    Session session = null;
12451    
12452                    try {
12453                            session = openSession();
12454    
12455                            MBMessage[] array = new MBMessageImpl[3];
12456    
12457                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
12458                                            classPK, status, orderByComparator, true);
12459    
12460                            array[1] = mbMessage;
12461    
12462                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
12463                                            classPK, status, orderByComparator, false);
12464    
12465                            return array;
12466                    }
12467                    catch (Exception e) {
12468                            throw processException(e);
12469                    }
12470                    finally {
12471                            closeSession(session);
12472                    }
12473            }
12474    
12475            protected MBMessage getByC_C_S_PrevAndNext(Session session,
12476                    MBMessage mbMessage, long classNameId, long classPK, int status,
12477                    OrderByComparator orderByComparator, boolean previous) {
12478                    StringBundler query = null;
12479    
12480                    if (orderByComparator != null) {
12481                            query = new StringBundler(6 +
12482                                            (orderByComparator.getOrderByFields().length * 6));
12483                    }
12484                    else {
12485                            query = new StringBundler(3);
12486                    }
12487    
12488                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12489    
12490                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
12491    
12492                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
12493    
12494                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
12495    
12496                    if (orderByComparator != null) {
12497                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12498    
12499                            if (orderByConditionFields.length > 0) {
12500                                    query.append(WHERE_AND);
12501                            }
12502    
12503                            for (int i = 0; i < orderByConditionFields.length; i++) {
12504                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12505                                    query.append(orderByConditionFields[i]);
12506    
12507                                    if ((i + 1) < orderByConditionFields.length) {
12508                                            if (orderByComparator.isAscending() ^ previous) {
12509                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12510                                            }
12511                                            else {
12512                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12513                                            }
12514                                    }
12515                                    else {
12516                                            if (orderByComparator.isAscending() ^ previous) {
12517                                                    query.append(WHERE_GREATER_THAN);
12518                                            }
12519                                            else {
12520                                                    query.append(WHERE_LESSER_THAN);
12521                                            }
12522                                    }
12523                            }
12524    
12525                            query.append(ORDER_BY_CLAUSE);
12526    
12527                            String[] orderByFields = orderByComparator.getOrderByFields();
12528    
12529                            for (int i = 0; i < orderByFields.length; i++) {
12530                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12531                                    query.append(orderByFields[i]);
12532    
12533                                    if ((i + 1) < orderByFields.length) {
12534                                            if (orderByComparator.isAscending() ^ previous) {
12535                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12536                                            }
12537                                            else {
12538                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12539                                            }
12540                                    }
12541                                    else {
12542                                            if (orderByComparator.isAscending() ^ previous) {
12543                                                    query.append(ORDER_BY_ASC);
12544                                            }
12545                                            else {
12546                                                    query.append(ORDER_BY_DESC);
12547                                            }
12548                                    }
12549                            }
12550                    }
12551    
12552                    else {
12553                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12554                    }
12555    
12556                    String sql = query.toString();
12557    
12558                    Query q = session.createQuery(sql);
12559    
12560                    q.setFirstResult(0);
12561                    q.setMaxResults(2);
12562    
12563                    QueryPos qPos = QueryPos.getInstance(q);
12564    
12565                    qPos.add(classNameId);
12566    
12567                    qPos.add(classPK);
12568    
12569                    qPos.add(status);
12570    
12571                    if (orderByComparator != null) {
12572                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12573    
12574                            for (Object value : values) {
12575                                    qPos.add(value);
12576                            }
12577                    }
12578    
12579                    List<MBMessage> list = q.list();
12580    
12581                    if (list.size() == 2) {
12582                            return list.get(1);
12583                    }
12584                    else {
12585                            return null;
12586                    }
12587            }
12588    
12589            /**
12590             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
12591             *
12592             * @param groupId the group ID
12593             * @param categoryId the category ID
12594             * @param threadId the thread ID
12595             * @param answer the answer
12596             * @return the matching message-boards messages
12597             * @throws SystemException if a system exception occurred
12598             */
12599            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
12600                    long threadId, boolean answer) throws SystemException {
12601                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
12602                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12603            }
12604    
12605            /**
12606             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
12607             *
12608             * <p>
12609             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12610             * </p>
12611             *
12612             * @param groupId the group ID
12613             * @param categoryId the category ID
12614             * @param threadId the thread ID
12615             * @param answer the answer
12616             * @param start the lower bound of the range of message-boards messages
12617             * @param end the upper bound of the range of message-boards messages (not inclusive)
12618             * @return the range of matching message-boards messages
12619             * @throws SystemException if a system exception occurred
12620             */
12621            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
12622                    long threadId, boolean answer, int start, int end)
12623                    throws SystemException {
12624                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
12625                            null);
12626            }
12627    
12628            /**
12629             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
12630             *
12631             * <p>
12632             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12633             * </p>
12634             *
12635             * @param groupId the group ID
12636             * @param categoryId the category ID
12637             * @param threadId the thread ID
12638             * @param answer the answer
12639             * @param start the lower bound of the range of message-boards messages
12640             * @param end the upper bound of the range of message-boards messages (not inclusive)
12641             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12642             * @return the ordered range of matching message-boards messages
12643             * @throws SystemException if a system exception occurred
12644             */
12645            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
12646                    long threadId, boolean answer, int start, int end,
12647                    OrderByComparator orderByComparator) throws SystemException {
12648                    FinderPath finderPath = null;
12649                    Object[] finderArgs = null;
12650    
12651                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12652                                    (orderByComparator == null)) {
12653                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
12654                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
12655                    }
12656                    else {
12657                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
12658                            finderArgs = new Object[] {
12659                                            groupId, categoryId, threadId, answer,
12660                                            
12661                                            start, end, orderByComparator
12662                                    };
12663                    }
12664    
12665                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12666                                    finderArgs, this);
12667    
12668                    if (list == null) {
12669                            StringBundler query = null;
12670    
12671                            if (orderByComparator != null) {
12672                                    query = new StringBundler(6 +
12673                                                    (orderByComparator.getOrderByFields().length * 3));
12674                            }
12675                            else {
12676                                    query = new StringBundler(6);
12677                            }
12678    
12679                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12680    
12681                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
12682    
12683                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
12684    
12685                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
12686    
12687                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
12688    
12689                            if (orderByComparator != null) {
12690                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12691                                            orderByComparator);
12692                            }
12693    
12694                            else {
12695                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12696                            }
12697    
12698                            String sql = query.toString();
12699    
12700                            Session session = null;
12701    
12702                            try {
12703                                    session = openSession();
12704    
12705                                    Query q = session.createQuery(sql);
12706    
12707                                    QueryPos qPos = QueryPos.getInstance(q);
12708    
12709                                    qPos.add(groupId);
12710    
12711                                    qPos.add(categoryId);
12712    
12713                                    qPos.add(threadId);
12714    
12715                                    qPos.add(answer);
12716    
12717                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
12718                                                    end);
12719                            }
12720                            catch (Exception e) {
12721                                    throw processException(e);
12722                            }
12723                            finally {
12724                                    if (list == null) {
12725                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
12726                                    }
12727                                    else {
12728                                            cacheResult(list);
12729    
12730                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
12731                                    }
12732    
12733                                    closeSession(session);
12734                            }
12735                    }
12736    
12737                    return list;
12738            }
12739    
12740            /**
12741             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
12742             *
12743             * <p>
12744             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12745             * </p>
12746             *
12747             * @param groupId the group ID
12748             * @param categoryId the category ID
12749             * @param threadId the thread ID
12750             * @param answer the answer
12751             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12752             * @return the first matching message-boards message
12753             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12754             * @throws SystemException if a system exception occurred
12755             */
12756            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
12757                    long threadId, boolean answer, OrderByComparator orderByComparator)
12758                    throws NoSuchMessageException, SystemException {
12759                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
12760                                    answer, 0, 1, orderByComparator);
12761    
12762                    if (list.isEmpty()) {
12763                            StringBundler msg = new StringBundler(10);
12764    
12765                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12766    
12767                            msg.append("groupId=");
12768                            msg.append(groupId);
12769    
12770                            msg.append(", categoryId=");
12771                            msg.append(categoryId);
12772    
12773                            msg.append(", threadId=");
12774                            msg.append(threadId);
12775    
12776                            msg.append(", answer=");
12777                            msg.append(answer);
12778    
12779                            msg.append(StringPool.CLOSE_CURLY_BRACE);
12780    
12781                            throw new NoSuchMessageException(msg.toString());
12782                    }
12783                    else {
12784                            return list.get(0);
12785                    }
12786            }
12787    
12788            /**
12789             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
12790             *
12791             * <p>
12792             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12793             * </p>
12794             *
12795             * @param groupId the group ID
12796             * @param categoryId the category ID
12797             * @param threadId the thread ID
12798             * @param answer the answer
12799             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12800             * @return the last matching message-boards message
12801             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12802             * @throws SystemException if a system exception occurred
12803             */
12804            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
12805                    long threadId, boolean answer, OrderByComparator orderByComparator)
12806                    throws NoSuchMessageException, SystemException {
12807                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
12808    
12809                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
12810                                    answer, count - 1, count, orderByComparator);
12811    
12812                    if (list.isEmpty()) {
12813                            StringBundler msg = new StringBundler(10);
12814    
12815                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12816    
12817                            msg.append("groupId=");
12818                            msg.append(groupId);
12819    
12820                            msg.append(", categoryId=");
12821                            msg.append(categoryId);
12822    
12823                            msg.append(", threadId=");
12824                            msg.append(threadId);
12825    
12826                            msg.append(", answer=");
12827                            msg.append(answer);
12828    
12829                            msg.append(StringPool.CLOSE_CURLY_BRACE);
12830    
12831                            throw new NoSuchMessageException(msg.toString());
12832                    }
12833                    else {
12834                            return list.get(0);
12835                    }
12836            }
12837    
12838            /**
12839             * 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;.
12840             *
12841             * <p>
12842             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12843             * </p>
12844             *
12845             * @param messageId the primary key of the current message-boards message
12846             * @param groupId the group ID
12847             * @param categoryId the category ID
12848             * @param threadId the thread ID
12849             * @param answer the answer
12850             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12851             * @return the previous, current, and next message-boards message
12852             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12853             * @throws SystemException if a system exception occurred
12854             */
12855            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
12856                    long categoryId, long threadId, boolean answer,
12857                    OrderByComparator orderByComparator)
12858                    throws NoSuchMessageException, SystemException {
12859                    MBMessage mbMessage = findByPrimaryKey(messageId);
12860    
12861                    Session session = null;
12862    
12863                    try {
12864                            session = openSession();
12865    
12866                            MBMessage[] array = new MBMessageImpl[3];
12867    
12868                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
12869                                            categoryId, threadId, answer, orderByComparator, true);
12870    
12871                            array[1] = mbMessage;
12872    
12873                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
12874                                            categoryId, threadId, answer, orderByComparator, false);
12875    
12876                            return array;
12877                    }
12878                    catch (Exception e) {
12879                            throw processException(e);
12880                    }
12881                    finally {
12882                            closeSession(session);
12883                    }
12884            }
12885    
12886            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
12887                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12888                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
12889                    StringBundler query = null;
12890    
12891                    if (orderByComparator != null) {
12892                            query = new StringBundler(6 +
12893                                            (orderByComparator.getOrderByFields().length * 6));
12894                    }
12895                    else {
12896                            query = new StringBundler(3);
12897                    }
12898    
12899                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12900    
12901                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
12902    
12903                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
12904    
12905                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
12906    
12907                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
12908    
12909                    if (orderByComparator != null) {
12910                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12911    
12912                            if (orderByConditionFields.length > 0) {
12913                                    query.append(WHERE_AND);
12914                            }
12915    
12916                            for (int i = 0; i < orderByConditionFields.length; i++) {
12917                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12918                                    query.append(orderByConditionFields[i]);
12919    
12920                                    if ((i + 1) < orderByConditionFields.length) {
12921                                            if (orderByComparator.isAscending() ^ previous) {
12922                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12923                                            }
12924                                            else {
12925                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12926                                            }
12927                                    }
12928                                    else {
12929                                            if (orderByComparator.isAscending() ^ previous) {
12930                                                    query.append(WHERE_GREATER_THAN);
12931                                            }
12932                                            else {
12933                                                    query.append(WHERE_LESSER_THAN);
12934                                            }
12935                                    }
12936                            }
12937    
12938                            query.append(ORDER_BY_CLAUSE);
12939    
12940                            String[] orderByFields = orderByComparator.getOrderByFields();
12941    
12942                            for (int i = 0; i < orderByFields.length; i++) {
12943                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12944                                    query.append(orderByFields[i]);
12945    
12946                                    if ((i + 1) < orderByFields.length) {
12947                                            if (orderByComparator.isAscending() ^ previous) {
12948                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12949                                            }
12950                                            else {
12951                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12952                                            }
12953                                    }
12954                                    else {
12955                                            if (orderByComparator.isAscending() ^ previous) {
12956                                                    query.append(ORDER_BY_ASC);
12957                                            }
12958                                            else {
12959                                                    query.append(ORDER_BY_DESC);
12960                                            }
12961                                    }
12962                            }
12963                    }
12964    
12965                    else {
12966                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12967                    }
12968    
12969                    String sql = query.toString();
12970    
12971                    Query q = session.createQuery(sql);
12972    
12973                    q.setFirstResult(0);
12974                    q.setMaxResults(2);
12975    
12976                    QueryPos qPos = QueryPos.getInstance(q);
12977    
12978                    qPos.add(groupId);
12979    
12980                    qPos.add(categoryId);
12981    
12982                    qPos.add(threadId);
12983    
12984                    qPos.add(answer);
12985    
12986                    if (orderByComparator != null) {
12987                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12988    
12989                            for (Object value : values) {
12990                                    qPos.add(value);
12991                            }
12992                    }
12993    
12994                    List<MBMessage> list = q.list();
12995    
12996                    if (list.size() == 2) {
12997                            return list.get(1);
12998                    }
12999                    else {
13000                            return null;
13001                    }
13002            }
13003    
13004            /**
13005             * 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;.
13006             *
13007             * @param groupId the group ID
13008             * @param categoryId the category ID
13009             * @param threadId the thread ID
13010             * @param answer the answer
13011             * @return the matching message-boards messages that the user has permission to view
13012             * @throws SystemException if a system exception occurred
13013             */
13014            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
13015                    long threadId, boolean answer) throws SystemException {
13016                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
13017                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13018            }
13019    
13020            /**
13021             * 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;.
13022             *
13023             * <p>
13024             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13025             * </p>
13026             *
13027             * @param groupId the group ID
13028             * @param categoryId the category ID
13029             * @param threadId the thread ID
13030             * @param answer the answer
13031             * @param start the lower bound of the range of message-boards messages
13032             * @param end the upper bound of the range of message-boards messages (not inclusive)
13033             * @return the range of matching message-boards messages that the user has permission to view
13034             * @throws SystemException if a system exception occurred
13035             */
13036            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
13037                    long threadId, boolean answer, int start, int end)
13038                    throws SystemException {
13039                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
13040                            start, end, null);
13041            }
13042    
13043            /**
13044             * 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;.
13045             *
13046             * <p>
13047             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13048             * </p>
13049             *
13050             * @param groupId the group ID
13051             * @param categoryId the category ID
13052             * @param threadId the thread ID
13053             * @param answer the answer
13054             * @param start the lower bound of the range of message-boards messages
13055             * @param end the upper bound of the range of message-boards messages (not inclusive)
13056             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13057             * @return the ordered range of matching message-boards messages that the user has permission to view
13058             * @throws SystemException if a system exception occurred
13059             */
13060            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
13061                    long threadId, boolean answer, int start, int end,
13062                    OrderByComparator orderByComparator) throws SystemException {
13063                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13064                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
13065                                    end, orderByComparator);
13066                    }
13067    
13068                    StringBundler query = null;
13069    
13070                    if (orderByComparator != null) {
13071                            query = new StringBundler(6 +
13072                                            (orderByComparator.getOrderByFields().length * 3));
13073                    }
13074                    else {
13075                            query = new StringBundler(6);
13076                    }
13077    
13078                    if (getDB().isSupportsInlineDistinct()) {
13079                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13080                    }
13081                    else {
13082                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13083                    }
13084    
13085                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
13086    
13087                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
13088    
13089                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
13090    
13091                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
13092    
13093                    if (!getDB().isSupportsInlineDistinct()) {
13094                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13095                    }
13096    
13097                    if (orderByComparator != null) {
13098                            if (getDB().isSupportsInlineDistinct()) {
13099                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13100                                            orderByComparator);
13101                            }
13102                            else {
13103                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13104                                            orderByComparator);
13105                            }
13106                    }
13107    
13108                    else {
13109                            if (getDB().isSupportsInlineDistinct()) {
13110                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13111                            }
13112                            else {
13113                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13114                            }
13115                    }
13116    
13117                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13118                                    MBMessage.class.getName(),
13119                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13120    
13121                    Session session = null;
13122    
13123                    try {
13124                            session = openSession();
13125    
13126                            SQLQuery q = session.createSQLQuery(sql);
13127    
13128                            if (getDB().isSupportsInlineDistinct()) {
13129                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13130                            }
13131                            else {
13132                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13133                            }
13134    
13135                            QueryPos qPos = QueryPos.getInstance(q);
13136    
13137                            qPos.add(groupId);
13138    
13139                            qPos.add(categoryId);
13140    
13141                            qPos.add(threadId);
13142    
13143                            qPos.add(answer);
13144    
13145                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
13146                    }
13147                    catch (Exception e) {
13148                            throw processException(e);
13149                    }
13150                    finally {
13151                            closeSession(session);
13152                    }
13153            }
13154    
13155            /**
13156             * 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;.
13157             *
13158             * @param messageId the primary key of the current message-boards message
13159             * @param groupId the group ID
13160             * @param categoryId the category ID
13161             * @param threadId the thread ID
13162             * @param answer the answer
13163             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13164             * @return the previous, current, and next message-boards message
13165             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13166             * @throws SystemException if a system exception occurred
13167             */
13168            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
13169                    long groupId, long categoryId, long threadId, boolean answer,
13170                    OrderByComparator orderByComparator)
13171                    throws NoSuchMessageException, SystemException {
13172                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13173                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
13174                                    threadId, answer, orderByComparator);
13175                    }
13176    
13177                    MBMessage mbMessage = findByPrimaryKey(messageId);
13178    
13179                    Session session = null;
13180    
13181                    try {
13182                            session = openSession();
13183    
13184                            MBMessage[] array = new MBMessageImpl[3];
13185    
13186                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
13187                                            groupId, categoryId, threadId, answer, orderByComparator,
13188                                            true);
13189    
13190                            array[1] = mbMessage;
13191    
13192                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
13193                                            groupId, categoryId, threadId, answer, orderByComparator,
13194                                            false);
13195    
13196                            return array;
13197                    }
13198                    catch (Exception e) {
13199                            throw processException(e);
13200                    }
13201                    finally {
13202                            closeSession(session);
13203                    }
13204            }
13205    
13206            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
13207                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
13208                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
13209                    StringBundler query = null;
13210    
13211                    if (orderByComparator != null) {
13212                            query = new StringBundler(6 +
13213                                            (orderByComparator.getOrderByFields().length * 6));
13214                    }
13215                    else {
13216                            query = new StringBundler(3);
13217                    }
13218    
13219                    if (getDB().isSupportsInlineDistinct()) {
13220                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13221                    }
13222                    else {
13223                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13224                    }
13225    
13226                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
13227    
13228                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
13229    
13230                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
13231    
13232                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
13233    
13234                    if (!getDB().isSupportsInlineDistinct()) {
13235                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13236                    }
13237    
13238                    if (orderByComparator != null) {
13239                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13240    
13241                            if (orderByConditionFields.length > 0) {
13242                                    query.append(WHERE_AND);
13243                            }
13244    
13245                            for (int i = 0; i < orderByConditionFields.length; i++) {
13246                                    if (getDB().isSupportsInlineDistinct()) {
13247                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13248                                    }
13249                                    else {
13250                                            query.append(_ORDER_BY_ENTITY_TABLE);
13251                                    }
13252    
13253                                    query.append(orderByConditionFields[i]);
13254    
13255                                    if ((i + 1) < orderByConditionFields.length) {
13256                                            if (orderByComparator.isAscending() ^ previous) {
13257                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13258                                            }
13259                                            else {
13260                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13261                                            }
13262                                    }
13263                                    else {
13264                                            if (orderByComparator.isAscending() ^ previous) {
13265                                                    query.append(WHERE_GREATER_THAN);
13266                                            }
13267                                            else {
13268                                                    query.append(WHERE_LESSER_THAN);
13269                                            }
13270                                    }
13271                            }
13272    
13273                            query.append(ORDER_BY_CLAUSE);
13274    
13275                            String[] orderByFields = orderByComparator.getOrderByFields();
13276    
13277                            for (int i = 0; i < orderByFields.length; i++) {
13278                                    if (getDB().isSupportsInlineDistinct()) {
13279                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13280                                    }
13281                                    else {
13282                                            query.append(_ORDER_BY_ENTITY_TABLE);
13283                                    }
13284    
13285                                    query.append(orderByFields[i]);
13286    
13287                                    if ((i + 1) < orderByFields.length) {
13288                                            if (orderByComparator.isAscending() ^ previous) {
13289                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13290                                            }
13291                                            else {
13292                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13293                                            }
13294                                    }
13295                                    else {
13296                                            if (orderByComparator.isAscending() ^ previous) {
13297                                                    query.append(ORDER_BY_ASC);
13298                                            }
13299                                            else {
13300                                                    query.append(ORDER_BY_DESC);
13301                                            }
13302                                    }
13303                            }
13304                    }
13305    
13306                    else {
13307                            if (getDB().isSupportsInlineDistinct()) {
13308                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13309                            }
13310                            else {
13311                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13312                            }
13313                    }
13314    
13315                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13316                                    MBMessage.class.getName(),
13317                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13318    
13319                    SQLQuery q = session.createSQLQuery(sql);
13320    
13321                    q.setFirstResult(0);
13322                    q.setMaxResults(2);
13323    
13324                    if (getDB().isSupportsInlineDistinct()) {
13325                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13326                    }
13327                    else {
13328                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13329                    }
13330    
13331                    QueryPos qPos = QueryPos.getInstance(q);
13332    
13333                    qPos.add(groupId);
13334    
13335                    qPos.add(categoryId);
13336    
13337                    qPos.add(threadId);
13338    
13339                    qPos.add(answer);
13340    
13341                    if (orderByComparator != null) {
13342                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13343    
13344                            for (Object value : values) {
13345                                    qPos.add(value);
13346                            }
13347                    }
13348    
13349                    List<MBMessage> list = q.list();
13350    
13351                    if (list.size() == 2) {
13352                            return list.get(1);
13353                    }
13354                    else {
13355                            return null;
13356                    }
13357            }
13358    
13359            /**
13360             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
13361             *
13362             * @param groupId the group ID
13363             * @param categoryId the category ID
13364             * @param threadId the thread ID
13365             * @param status the status
13366             * @return the matching message-boards messages
13367             * @throws SystemException if a system exception occurred
13368             */
13369            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
13370                    long threadId, int status) throws SystemException {
13371                    return findByG_C_T_S(groupId, categoryId, threadId, status,
13372                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13373            }
13374    
13375            /**
13376             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
13377             *
13378             * <p>
13379             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13380             * </p>
13381             *
13382             * @param groupId the group ID
13383             * @param categoryId the category ID
13384             * @param threadId the thread ID
13385             * @param status the status
13386             * @param start the lower bound of the range of message-boards messages
13387             * @param end the upper bound of the range of message-boards messages (not inclusive)
13388             * @return the range of matching message-boards messages
13389             * @throws SystemException if a system exception occurred
13390             */
13391            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
13392                    long threadId, int status, int start, int end)
13393                    throws SystemException {
13394                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
13395                            null);
13396            }
13397    
13398            /**
13399             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
13400             *
13401             * <p>
13402             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13403             * </p>
13404             *
13405             * @param groupId the group ID
13406             * @param categoryId the category ID
13407             * @param threadId the thread ID
13408             * @param status the status
13409             * @param start the lower bound of the range of message-boards messages
13410             * @param end the upper bound of the range of message-boards messages (not inclusive)
13411             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13412             * @return the ordered range of matching message-boards messages
13413             * @throws SystemException if a system exception occurred
13414             */
13415            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
13416                    long threadId, int status, int start, int end,
13417                    OrderByComparator orderByComparator) throws SystemException {
13418                    FinderPath finderPath = null;
13419                    Object[] finderArgs = null;
13420    
13421                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13422                                    (orderByComparator == null)) {
13423                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
13424                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
13425                    }
13426                    else {
13427                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
13428                            finderArgs = new Object[] {
13429                                            groupId, categoryId, threadId, status,
13430                                            
13431                                            start, end, orderByComparator
13432                                    };
13433                    }
13434    
13435                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
13436                                    finderArgs, this);
13437    
13438                    if (list == null) {
13439                            StringBundler query = null;
13440    
13441                            if (orderByComparator != null) {
13442                                    query = new StringBundler(6 +
13443                                                    (orderByComparator.getOrderByFields().length * 3));
13444                            }
13445                            else {
13446                                    query = new StringBundler(6);
13447                            }
13448    
13449                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13450    
13451                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
13452    
13453                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
13454    
13455                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
13456    
13457                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
13458    
13459                            if (orderByComparator != null) {
13460                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13461                                            orderByComparator);
13462                            }
13463    
13464                            else {
13465                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13466                            }
13467    
13468                            String sql = query.toString();
13469    
13470                            Session session = null;
13471    
13472                            try {
13473                                    session = openSession();
13474    
13475                                    Query q = session.createQuery(sql);
13476    
13477                                    QueryPos qPos = QueryPos.getInstance(q);
13478    
13479                                    qPos.add(groupId);
13480    
13481                                    qPos.add(categoryId);
13482    
13483                                    qPos.add(threadId);
13484    
13485                                    qPos.add(status);
13486    
13487                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
13488                                                    end);
13489                            }
13490                            catch (Exception e) {
13491                                    throw processException(e);
13492                            }
13493                            finally {
13494                                    if (list == null) {
13495                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
13496                                    }
13497                                    else {
13498                                            cacheResult(list);
13499    
13500                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
13501                                    }
13502    
13503                                    closeSession(session);
13504                            }
13505                    }
13506    
13507                    return list;
13508            }
13509    
13510            /**
13511             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
13512             *
13513             * <p>
13514             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13515             * </p>
13516             *
13517             * @param groupId the group ID
13518             * @param categoryId the category ID
13519             * @param threadId the thread ID
13520             * @param status the status
13521             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13522             * @return the first matching message-boards message
13523             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13524             * @throws SystemException if a system exception occurred
13525             */
13526            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
13527                    long threadId, int status, OrderByComparator orderByComparator)
13528                    throws NoSuchMessageException, SystemException {
13529                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
13530                                    status, 0, 1, orderByComparator);
13531    
13532                    if (list.isEmpty()) {
13533                            StringBundler msg = new StringBundler(10);
13534    
13535                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13536    
13537                            msg.append("groupId=");
13538                            msg.append(groupId);
13539    
13540                            msg.append(", categoryId=");
13541                            msg.append(categoryId);
13542    
13543                            msg.append(", threadId=");
13544                            msg.append(threadId);
13545    
13546                            msg.append(", status=");
13547                            msg.append(status);
13548    
13549                            msg.append(StringPool.CLOSE_CURLY_BRACE);
13550    
13551                            throw new NoSuchMessageException(msg.toString());
13552                    }
13553                    else {
13554                            return list.get(0);
13555                    }
13556            }
13557    
13558            /**
13559             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
13560             *
13561             * <p>
13562             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13563             * </p>
13564             *
13565             * @param groupId the group ID
13566             * @param categoryId the category ID
13567             * @param threadId the thread ID
13568             * @param status the status
13569             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13570             * @return the last matching message-boards message
13571             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13572             * @throws SystemException if a system exception occurred
13573             */
13574            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
13575                    long threadId, int status, OrderByComparator orderByComparator)
13576                    throws NoSuchMessageException, SystemException {
13577                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
13578    
13579                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
13580                                    status, count - 1, count, orderByComparator);
13581    
13582                    if (list.isEmpty()) {
13583                            StringBundler msg = new StringBundler(10);
13584    
13585                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13586    
13587                            msg.append("groupId=");
13588                            msg.append(groupId);
13589    
13590                            msg.append(", categoryId=");
13591                            msg.append(categoryId);
13592    
13593                            msg.append(", threadId=");
13594                            msg.append(threadId);
13595    
13596                            msg.append(", status=");
13597                            msg.append(status);
13598    
13599                            msg.append(StringPool.CLOSE_CURLY_BRACE);
13600    
13601                            throw new NoSuchMessageException(msg.toString());
13602                    }
13603                    else {
13604                            return list.get(0);
13605                    }
13606            }
13607    
13608            /**
13609             * 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;.
13610             *
13611             * <p>
13612             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13613             * </p>
13614             *
13615             * @param messageId the primary key of the current message-boards message
13616             * @param groupId the group ID
13617             * @param categoryId the category ID
13618             * @param threadId the thread ID
13619             * @param status the status
13620             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13621             * @return the previous, current, and next message-boards message
13622             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13623             * @throws SystemException if a system exception occurred
13624             */
13625            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
13626                    long categoryId, long threadId, int status,
13627                    OrderByComparator orderByComparator)
13628                    throws NoSuchMessageException, SystemException {
13629                    MBMessage mbMessage = findByPrimaryKey(messageId);
13630    
13631                    Session session = null;
13632    
13633                    try {
13634                            session = openSession();
13635    
13636                            MBMessage[] array = new MBMessageImpl[3];
13637    
13638                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
13639                                            categoryId, threadId, status, orderByComparator, true);
13640    
13641                            array[1] = mbMessage;
13642    
13643                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
13644                                            categoryId, threadId, status, orderByComparator, false);
13645    
13646                            return array;
13647                    }
13648                    catch (Exception e) {
13649                            throw processException(e);
13650                    }
13651                    finally {
13652                            closeSession(session);
13653                    }
13654            }
13655    
13656            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
13657                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
13658                    int status, OrderByComparator orderByComparator, boolean previous) {
13659                    StringBundler query = null;
13660    
13661                    if (orderByComparator != null) {
13662                            query = new StringBundler(6 +
13663                                            (orderByComparator.getOrderByFields().length * 6));
13664                    }
13665                    else {
13666                            query = new StringBundler(3);
13667                    }
13668    
13669                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13670    
13671                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
13672    
13673                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
13674    
13675                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
13676    
13677                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
13678    
13679                    if (orderByComparator != null) {
13680                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13681    
13682                            if (orderByConditionFields.length > 0) {
13683                                    query.append(WHERE_AND);
13684                            }
13685    
13686                            for (int i = 0; i < orderByConditionFields.length; i++) {
13687                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13688                                    query.append(orderByConditionFields[i]);
13689    
13690                                    if ((i + 1) < orderByConditionFields.length) {
13691                                            if (orderByComparator.isAscending() ^ previous) {
13692                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13693                                            }
13694                                            else {
13695                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13696                                            }
13697                                    }
13698                                    else {
13699                                            if (orderByComparator.isAscending() ^ previous) {
13700                                                    query.append(WHERE_GREATER_THAN);
13701                                            }
13702                                            else {
13703                                                    query.append(WHERE_LESSER_THAN);
13704                                            }
13705                                    }
13706                            }
13707    
13708                            query.append(ORDER_BY_CLAUSE);
13709    
13710                            String[] orderByFields = orderByComparator.getOrderByFields();
13711    
13712                            for (int i = 0; i < orderByFields.length; i++) {
13713                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13714                                    query.append(orderByFields[i]);
13715    
13716                                    if ((i + 1) < orderByFields.length) {
13717                                            if (orderByComparator.isAscending() ^ previous) {
13718                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13719                                            }
13720                                            else {
13721                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13722                                            }
13723                                    }
13724                                    else {
13725                                            if (orderByComparator.isAscending() ^ previous) {
13726                                                    query.append(ORDER_BY_ASC);
13727                                            }
13728                                            else {
13729                                                    query.append(ORDER_BY_DESC);
13730                                            }
13731                                    }
13732                            }
13733                    }
13734    
13735                    else {
13736                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13737                    }
13738    
13739                    String sql = query.toString();
13740    
13741                    Query q = session.createQuery(sql);
13742    
13743                    q.setFirstResult(0);
13744                    q.setMaxResults(2);
13745    
13746                    QueryPos qPos = QueryPos.getInstance(q);
13747    
13748                    qPos.add(groupId);
13749    
13750                    qPos.add(categoryId);
13751    
13752                    qPos.add(threadId);
13753    
13754                    qPos.add(status);
13755    
13756                    if (orderByComparator != null) {
13757                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13758    
13759                            for (Object value : values) {
13760                                    qPos.add(value);
13761                            }
13762                    }
13763    
13764                    List<MBMessage> list = q.list();
13765    
13766                    if (list.size() == 2) {
13767                            return list.get(1);
13768                    }
13769                    else {
13770                            return null;
13771                    }
13772            }
13773    
13774            /**
13775             * 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;.
13776             *
13777             * @param groupId the group ID
13778             * @param categoryId the category ID
13779             * @param threadId the thread ID
13780             * @param status the status
13781             * @return the matching message-boards messages that the user has permission to view
13782             * @throws SystemException if a system exception occurred
13783             */
13784            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
13785                    long threadId, int status) throws SystemException {
13786                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
13787                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13788            }
13789    
13790            /**
13791             * 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;.
13792             *
13793             * <p>
13794             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13795             * </p>
13796             *
13797             * @param groupId the group ID
13798             * @param categoryId the category ID
13799             * @param threadId the thread ID
13800             * @param status the status
13801             * @param start the lower bound of the range of message-boards messages
13802             * @param end the upper bound of the range of message-boards messages (not inclusive)
13803             * @return the range of matching message-boards messages that the user has permission to view
13804             * @throws SystemException if a system exception occurred
13805             */
13806            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
13807                    long threadId, int status, int start, int end)
13808                    throws SystemException {
13809                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
13810                            start, end, null);
13811            }
13812    
13813            /**
13814             * 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;.
13815             *
13816             * <p>
13817             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13818             * </p>
13819             *
13820             * @param groupId the group ID
13821             * @param categoryId the category ID
13822             * @param threadId the thread ID
13823             * @param status the status
13824             * @param start the lower bound of the range of message-boards messages
13825             * @param end the upper bound of the range of message-boards messages (not inclusive)
13826             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13827             * @return the ordered range of matching message-boards messages that the user has permission to view
13828             * @throws SystemException if a system exception occurred
13829             */
13830            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
13831                    long threadId, int status, int start, int end,
13832                    OrderByComparator orderByComparator) throws SystemException {
13833                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13834                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
13835                                    end, orderByComparator);
13836                    }
13837    
13838                    StringBundler query = null;
13839    
13840                    if (orderByComparator != null) {
13841                            query = new StringBundler(6 +
13842                                            (orderByComparator.getOrderByFields().length * 3));
13843                    }
13844                    else {
13845                            query = new StringBundler(6);
13846                    }
13847    
13848                    if (getDB().isSupportsInlineDistinct()) {
13849                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13850                    }
13851                    else {
13852                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13853                    }
13854    
13855                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
13856    
13857                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
13858    
13859                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
13860    
13861                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
13862    
13863                    if (!getDB().isSupportsInlineDistinct()) {
13864                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13865                    }
13866    
13867                    if (orderByComparator != null) {
13868                            if (getDB().isSupportsInlineDistinct()) {
13869                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13870                                            orderByComparator);
13871                            }
13872                            else {
13873                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13874                                            orderByComparator);
13875                            }
13876                    }
13877    
13878                    else {
13879                            if (getDB().isSupportsInlineDistinct()) {
13880                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13881                            }
13882                            else {
13883                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13884                            }
13885                    }
13886    
13887                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13888                                    MBMessage.class.getName(),
13889                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13890    
13891                    Session session = null;
13892    
13893                    try {
13894                            session = openSession();
13895    
13896                            SQLQuery q = session.createSQLQuery(sql);
13897    
13898                            if (getDB().isSupportsInlineDistinct()) {
13899                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13900                            }
13901                            else {
13902                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13903                            }
13904    
13905                            QueryPos qPos = QueryPos.getInstance(q);
13906    
13907                            qPos.add(groupId);
13908    
13909                            qPos.add(categoryId);
13910    
13911                            qPos.add(threadId);
13912    
13913                            qPos.add(status);
13914    
13915                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
13916                    }
13917                    catch (Exception e) {
13918                            throw processException(e);
13919                    }
13920                    finally {
13921                            closeSession(session);
13922                    }
13923            }
13924    
13925            /**
13926             * 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;.
13927             *
13928             * @param messageId the primary key of the current message-boards message
13929             * @param groupId the group ID
13930             * @param categoryId the category ID
13931             * @param threadId the thread ID
13932             * @param status the status
13933             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13934             * @return the previous, current, and next message-boards message
13935             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13936             * @throws SystemException if a system exception occurred
13937             */
13938            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
13939                    long groupId, long categoryId, long threadId, int status,
13940                    OrderByComparator orderByComparator)
13941                    throws NoSuchMessageException, SystemException {
13942                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13943                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
13944                                    threadId, status, orderByComparator);
13945                    }
13946    
13947                    MBMessage mbMessage = findByPrimaryKey(messageId);
13948    
13949                    Session session = null;
13950    
13951                    try {
13952                            session = openSession();
13953    
13954                            MBMessage[] array = new MBMessageImpl[3];
13955    
13956                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
13957                                            groupId, categoryId, threadId, status, orderByComparator,
13958                                            true);
13959    
13960                            array[1] = mbMessage;
13961    
13962                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
13963                                            groupId, categoryId, threadId, status, orderByComparator,
13964                                            false);
13965    
13966                            return array;
13967                    }
13968                    catch (Exception e) {
13969                            throw processException(e);
13970                    }
13971                    finally {
13972                            closeSession(session);
13973                    }
13974            }
13975    
13976            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
13977                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
13978                    int status, OrderByComparator orderByComparator, boolean previous) {
13979                    StringBundler query = null;
13980    
13981                    if (orderByComparator != null) {
13982                            query = new StringBundler(6 +
13983                                            (orderByComparator.getOrderByFields().length * 6));
13984                    }
13985                    else {
13986                            query = new StringBundler(3);
13987                    }
13988    
13989                    if (getDB().isSupportsInlineDistinct()) {
13990                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13991                    }
13992                    else {
13993                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13994                    }
13995    
13996                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
13997    
13998                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
13999    
14000                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
14001    
14002                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
14003    
14004                    if (!getDB().isSupportsInlineDistinct()) {
14005                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
14006                    }
14007    
14008                    if (orderByComparator != null) {
14009                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14010    
14011                            if (orderByConditionFields.length > 0) {
14012                                    query.append(WHERE_AND);
14013                            }
14014    
14015                            for (int i = 0; i < orderByConditionFields.length; i++) {
14016                                    if (getDB().isSupportsInlineDistinct()) {
14017                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14018                                    }
14019                                    else {
14020                                            query.append(_ORDER_BY_ENTITY_TABLE);
14021                                    }
14022    
14023                                    query.append(orderByConditionFields[i]);
14024    
14025                                    if ((i + 1) < orderByConditionFields.length) {
14026                                            if (orderByComparator.isAscending() ^ previous) {
14027                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14028                                            }
14029                                            else {
14030                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14031                                            }
14032                                    }
14033                                    else {
14034                                            if (orderByComparator.isAscending() ^ previous) {
14035                                                    query.append(WHERE_GREATER_THAN);
14036                                            }
14037                                            else {
14038                                                    query.append(WHERE_LESSER_THAN);
14039                                            }
14040                                    }
14041                            }
14042    
14043                            query.append(ORDER_BY_CLAUSE);
14044    
14045                            String[] orderByFields = orderByComparator.getOrderByFields();
14046    
14047                            for (int i = 0; i < orderByFields.length; i++) {
14048                                    if (getDB().isSupportsInlineDistinct()) {
14049                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14050                                    }
14051                                    else {
14052                                            query.append(_ORDER_BY_ENTITY_TABLE);
14053                                    }
14054    
14055                                    query.append(orderByFields[i]);
14056    
14057                                    if ((i + 1) < orderByFields.length) {
14058                                            if (orderByComparator.isAscending() ^ previous) {
14059                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14060                                            }
14061                                            else {
14062                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14063                                            }
14064                                    }
14065                                    else {
14066                                            if (orderByComparator.isAscending() ^ previous) {
14067                                                    query.append(ORDER_BY_ASC);
14068                                            }
14069                                            else {
14070                                                    query.append(ORDER_BY_DESC);
14071                                            }
14072                                    }
14073                            }
14074                    }
14075    
14076                    else {
14077                            if (getDB().isSupportsInlineDistinct()) {
14078                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14079                            }
14080                            else {
14081                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
14082                            }
14083                    }
14084    
14085                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14086                                    MBMessage.class.getName(),
14087                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14088    
14089                    SQLQuery q = session.createSQLQuery(sql);
14090    
14091                    q.setFirstResult(0);
14092                    q.setMaxResults(2);
14093    
14094                    if (getDB().isSupportsInlineDistinct()) {
14095                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
14096                    }
14097                    else {
14098                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
14099                    }
14100    
14101                    QueryPos qPos = QueryPos.getInstance(q);
14102    
14103                    qPos.add(groupId);
14104    
14105                    qPos.add(categoryId);
14106    
14107                    qPos.add(threadId);
14108    
14109                    qPos.add(status);
14110    
14111                    if (orderByComparator != null) {
14112                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14113    
14114                            for (Object value : values) {
14115                                    qPos.add(value);
14116                            }
14117                    }
14118    
14119                    List<MBMessage> list = q.list();
14120    
14121                    if (list.size() == 2) {
14122                            return list.get(1);
14123                    }
14124                    else {
14125                            return null;
14126                    }
14127            }
14128    
14129            /**
14130             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
14131             *
14132             * @param userId the user ID
14133             * @param classNameId the class name ID
14134             * @param classPK the class p k
14135             * @param status the status
14136             * @return the matching message-boards messages
14137             * @throws SystemException if a system exception occurred
14138             */
14139            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
14140                    long classPK, int status) throws SystemException {
14141                    return findByU_C_C_S(userId, classNameId, classPK, status,
14142                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14143            }
14144    
14145            /**
14146             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
14147             *
14148             * <p>
14149             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14150             * </p>
14151             *
14152             * @param userId the user ID
14153             * @param classNameId the class name ID
14154             * @param classPK the class p k
14155             * @param status the status
14156             * @param start the lower bound of the range of message-boards messages
14157             * @param end the upper bound of the range of message-boards messages (not inclusive)
14158             * @return the range of matching message-boards messages
14159             * @throws SystemException if a system exception occurred
14160             */
14161            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
14162                    long classPK, int status, int start, int end) throws SystemException {
14163                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
14164                            null);
14165            }
14166    
14167            /**
14168             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
14169             *
14170             * <p>
14171             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14172             * </p>
14173             *
14174             * @param userId the user ID
14175             * @param classNameId the class name ID
14176             * @param classPK the class p k
14177             * @param status the status
14178             * @param start the lower bound of the range of message-boards messages
14179             * @param end the upper bound of the range of message-boards messages (not inclusive)
14180             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14181             * @return the ordered range of matching message-boards messages
14182             * @throws SystemException if a system exception occurred
14183             */
14184            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
14185                    long classPK, int status, int start, int end,
14186                    OrderByComparator orderByComparator) throws SystemException {
14187                    FinderPath finderPath = null;
14188                    Object[] finderArgs = null;
14189    
14190                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14191                                    (orderByComparator == null)) {
14192                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
14193                            finderArgs = new Object[] { userId, classNameId, classPK, status };
14194                    }
14195                    else {
14196                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
14197                            finderArgs = new Object[] {
14198                                            userId, classNameId, classPK, status,
14199                                            
14200                                            start, end, orderByComparator
14201                                    };
14202                    }
14203    
14204                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
14205                                    finderArgs, this);
14206    
14207                    if (list == null) {
14208                            StringBundler query = null;
14209    
14210                            if (orderByComparator != null) {
14211                                    query = new StringBundler(6 +
14212                                                    (orderByComparator.getOrderByFields().length * 3));
14213                            }
14214                            else {
14215                                    query = new StringBundler(6);
14216                            }
14217    
14218                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14219    
14220                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
14221    
14222                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
14223    
14224                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
14225    
14226                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
14227    
14228                            if (orderByComparator != null) {
14229                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14230                                            orderByComparator);
14231                            }
14232    
14233                            else {
14234                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14235                            }
14236    
14237                            String sql = query.toString();
14238    
14239                            Session session = null;
14240    
14241                            try {
14242                                    session = openSession();
14243    
14244                                    Query q = session.createQuery(sql);
14245    
14246                                    QueryPos qPos = QueryPos.getInstance(q);
14247    
14248                                    qPos.add(userId);
14249    
14250                                    qPos.add(classNameId);
14251    
14252                                    qPos.add(classPK);
14253    
14254                                    qPos.add(status);
14255    
14256                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
14257                                                    end);
14258                            }
14259                            catch (Exception e) {
14260                                    throw processException(e);
14261                            }
14262                            finally {
14263                                    if (list == null) {
14264                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
14265                                    }
14266                                    else {
14267                                            cacheResult(list);
14268    
14269                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
14270                                    }
14271    
14272                                    closeSession(session);
14273                            }
14274                    }
14275    
14276                    return list;
14277            }
14278    
14279            /**
14280             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
14281             *
14282             * <p>
14283             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14284             * </p>
14285             *
14286             * @param userId the user ID
14287             * @param classNameId the class name ID
14288             * @param classPK the class p k
14289             * @param status the status
14290             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14291             * @return the first matching message-boards message
14292             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14293             * @throws SystemException if a system exception occurred
14294             */
14295            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
14296                    long classPK, int status, OrderByComparator orderByComparator)
14297                    throws NoSuchMessageException, SystemException {
14298                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
14299                                    status, 0, 1, orderByComparator);
14300    
14301                    if (list.isEmpty()) {
14302                            StringBundler msg = new StringBundler(10);
14303    
14304                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14305    
14306                            msg.append("userId=");
14307                            msg.append(userId);
14308    
14309                            msg.append(", classNameId=");
14310                            msg.append(classNameId);
14311    
14312                            msg.append(", classPK=");
14313                            msg.append(classPK);
14314    
14315                            msg.append(", status=");
14316                            msg.append(status);
14317    
14318                            msg.append(StringPool.CLOSE_CURLY_BRACE);
14319    
14320                            throw new NoSuchMessageException(msg.toString());
14321                    }
14322                    else {
14323                            return list.get(0);
14324                    }
14325            }
14326    
14327            /**
14328             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
14329             *
14330             * <p>
14331             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14332             * </p>
14333             *
14334             * @param userId the user ID
14335             * @param classNameId the class name ID
14336             * @param classPK the class p k
14337             * @param status the status
14338             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14339             * @return the last matching message-boards message
14340             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14341             * @throws SystemException if a system exception occurred
14342             */
14343            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
14344                    long classPK, int status, OrderByComparator orderByComparator)
14345                    throws NoSuchMessageException, SystemException {
14346                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
14347    
14348                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
14349                                    status, count - 1, count, orderByComparator);
14350    
14351                    if (list.isEmpty()) {
14352                            StringBundler msg = new StringBundler(10);
14353    
14354                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14355    
14356                            msg.append("userId=");
14357                            msg.append(userId);
14358    
14359                            msg.append(", classNameId=");
14360                            msg.append(classNameId);
14361    
14362                            msg.append(", classPK=");
14363                            msg.append(classPK);
14364    
14365                            msg.append(", status=");
14366                            msg.append(status);
14367    
14368                            msg.append(StringPool.CLOSE_CURLY_BRACE);
14369    
14370                            throw new NoSuchMessageException(msg.toString());
14371                    }
14372                    else {
14373                            return list.get(0);
14374                    }
14375            }
14376    
14377            /**
14378             * 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;.
14379             *
14380             * <p>
14381             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14382             * </p>
14383             *
14384             * @param messageId the primary key of the current message-boards message
14385             * @param userId the user ID
14386             * @param classNameId the class name ID
14387             * @param classPK the class p k
14388             * @param status the status
14389             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14390             * @return the previous, current, and next message-boards message
14391             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14392             * @throws SystemException if a system exception occurred
14393             */
14394            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
14395                    long classNameId, long classPK, int status,
14396                    OrderByComparator orderByComparator)
14397                    throws NoSuchMessageException, SystemException {
14398                    MBMessage mbMessage = findByPrimaryKey(messageId);
14399    
14400                    Session session = null;
14401    
14402                    try {
14403                            session = openSession();
14404    
14405                            MBMessage[] array = new MBMessageImpl[3];
14406    
14407                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
14408                                            classNameId, classPK, status, orderByComparator, true);
14409    
14410                            array[1] = mbMessage;
14411    
14412                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
14413                                            classNameId, classPK, status, orderByComparator, false);
14414    
14415                            return array;
14416                    }
14417                    catch (Exception e) {
14418                            throw processException(e);
14419                    }
14420                    finally {
14421                            closeSession(session);
14422                    }
14423            }
14424    
14425            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
14426                    MBMessage mbMessage, long userId, long classNameId, long classPK,
14427                    int status, OrderByComparator orderByComparator, boolean previous) {
14428                    StringBundler query = null;
14429    
14430                    if (orderByComparator != null) {
14431                            query = new StringBundler(6 +
14432                                            (orderByComparator.getOrderByFields().length * 6));
14433                    }
14434                    else {
14435                            query = new StringBundler(3);
14436                    }
14437    
14438                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14439    
14440                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
14441    
14442                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
14443    
14444                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
14445    
14446                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
14447    
14448                    if (orderByComparator != null) {
14449                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14450    
14451                            if (orderByConditionFields.length > 0) {
14452                                    query.append(WHERE_AND);
14453                            }
14454    
14455                            for (int i = 0; i < orderByConditionFields.length; i++) {
14456                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14457                                    query.append(orderByConditionFields[i]);
14458    
14459                                    if ((i + 1) < orderByConditionFields.length) {
14460                                            if (orderByComparator.isAscending() ^ previous) {
14461                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14462                                            }
14463                                            else {
14464                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14465                                            }
14466                                    }
14467                                    else {
14468                                            if (orderByComparator.isAscending() ^ previous) {
14469                                                    query.append(WHERE_GREATER_THAN);
14470                                            }
14471                                            else {
14472                                                    query.append(WHERE_LESSER_THAN);
14473                                            }
14474                                    }
14475                            }
14476    
14477                            query.append(ORDER_BY_CLAUSE);
14478    
14479                            String[] orderByFields = orderByComparator.getOrderByFields();
14480    
14481                            for (int i = 0; i < orderByFields.length; i++) {
14482                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14483                                    query.append(orderByFields[i]);
14484    
14485                                    if ((i + 1) < orderByFields.length) {
14486                                            if (orderByComparator.isAscending() ^ previous) {
14487                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14488                                            }
14489                                            else {
14490                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14491                                            }
14492                                    }
14493                                    else {
14494                                            if (orderByComparator.isAscending() ^ previous) {
14495                                                    query.append(ORDER_BY_ASC);
14496                                            }
14497                                            else {
14498                                                    query.append(ORDER_BY_DESC);
14499                                            }
14500                                    }
14501                            }
14502                    }
14503    
14504                    else {
14505                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14506                    }
14507    
14508                    String sql = query.toString();
14509    
14510                    Query q = session.createQuery(sql);
14511    
14512                    q.setFirstResult(0);
14513                    q.setMaxResults(2);
14514    
14515                    QueryPos qPos = QueryPos.getInstance(q);
14516    
14517                    qPos.add(userId);
14518    
14519                    qPos.add(classNameId);
14520    
14521                    qPos.add(classPK);
14522    
14523                    qPos.add(status);
14524    
14525                    if (orderByComparator != null) {
14526                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14527    
14528                            for (Object value : values) {
14529                                    qPos.add(value);
14530                            }
14531                    }
14532    
14533                    List<MBMessage> list = q.list();
14534    
14535                    if (list.size() == 2) {
14536                            return list.get(1);
14537                    }
14538                    else {
14539                            return null;
14540                    }
14541            }
14542    
14543            /**
14544             * Returns all the message-boards messages.
14545             *
14546             * @return the message-boards messages
14547             * @throws SystemException if a system exception occurred
14548             */
14549            public List<MBMessage> findAll() throws SystemException {
14550                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14551            }
14552    
14553            /**
14554             * Returns a range of all the message-boards messages.
14555             *
14556             * <p>
14557             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14558             * </p>
14559             *
14560             * @param start the lower bound of the range of message-boards messages
14561             * @param end the upper bound of the range of message-boards messages (not inclusive)
14562             * @return the range of message-boards messages
14563             * @throws SystemException if a system exception occurred
14564             */
14565            public List<MBMessage> findAll(int start, int end)
14566                    throws SystemException {
14567                    return findAll(start, end, null);
14568            }
14569    
14570            /**
14571             * Returns an ordered range of all the message-boards messages.
14572             *
14573             * <p>
14574             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14575             * </p>
14576             *
14577             * @param start the lower bound of the range of message-boards messages
14578             * @param end the upper bound of the range of message-boards messages (not inclusive)
14579             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14580             * @return the ordered range of message-boards messages
14581             * @throws SystemException if a system exception occurred
14582             */
14583            public List<MBMessage> findAll(int start, int end,
14584                    OrderByComparator orderByComparator) throws SystemException {
14585                    FinderPath finderPath = null;
14586                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
14587    
14588                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14589                                    (orderByComparator == null)) {
14590                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
14591                            finderArgs = FINDER_ARGS_EMPTY;
14592                    }
14593                    else {
14594                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
14595                            finderArgs = new Object[] { start, end, orderByComparator };
14596                    }
14597    
14598                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
14599                                    finderArgs, this);
14600    
14601                    if (list == null) {
14602                            StringBundler query = null;
14603                            String sql = null;
14604    
14605                            if (orderByComparator != null) {
14606                                    query = new StringBundler(2 +
14607                                                    (orderByComparator.getOrderByFields().length * 3));
14608    
14609                                    query.append(_SQL_SELECT_MBMESSAGE);
14610    
14611                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14612                                            orderByComparator);
14613    
14614                                    sql = query.toString();
14615                            }
14616                            else {
14617                                    sql = _SQL_SELECT_MBMESSAGE.concat(MBMessageModelImpl.ORDER_BY_JPQL);
14618                            }
14619    
14620                            Session session = null;
14621    
14622                            try {
14623                                    session = openSession();
14624    
14625                                    Query q = session.createQuery(sql);
14626    
14627                                    if (orderByComparator == null) {
14628                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14629                                                            start, end, false);
14630    
14631                                            Collections.sort(list);
14632                                    }
14633                                    else {
14634                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14635                                                            start, end);
14636                                    }
14637                            }
14638                            catch (Exception e) {
14639                                    throw processException(e);
14640                            }
14641                            finally {
14642                                    if (list == null) {
14643                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
14644                                    }
14645                                    else {
14646                                            cacheResult(list);
14647    
14648                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
14649                                    }
14650    
14651                                    closeSession(session);
14652                            }
14653                    }
14654    
14655                    return list;
14656            }
14657    
14658            /**
14659             * Removes all the message-boards messages where uuid = &#63; from the database.
14660             *
14661             * @param uuid the uuid
14662             * @throws SystemException if a system exception occurred
14663             */
14664            public void removeByUuid(String uuid) throws SystemException {
14665                    for (MBMessage mbMessage : findByUuid(uuid)) {
14666                            mbMessagePersistence.remove(mbMessage);
14667                    }
14668            }
14669    
14670            /**
14671             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
14672             *
14673             * @param uuid the uuid
14674             * @param groupId the group ID
14675             * @throws SystemException if a system exception occurred
14676             */
14677            public void removeByUUID_G(String uuid, long groupId)
14678                    throws NoSuchMessageException, SystemException {
14679                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
14680    
14681                    mbMessagePersistence.remove(mbMessage);
14682            }
14683    
14684            /**
14685             * Removes all the message-boards messages where groupId = &#63; from the database.
14686             *
14687             * @param groupId the group ID
14688             * @throws SystemException if a system exception occurred
14689             */
14690            public void removeByGroupId(long groupId) throws SystemException {
14691                    for (MBMessage mbMessage : findByGroupId(groupId)) {
14692                            mbMessagePersistence.remove(mbMessage);
14693                    }
14694            }
14695    
14696            /**
14697             * Removes all the message-boards messages where companyId = &#63; from the database.
14698             *
14699             * @param companyId the company ID
14700             * @throws SystemException if a system exception occurred
14701             */
14702            public void removeByCompanyId(long companyId) throws SystemException {
14703                    for (MBMessage mbMessage : findByCompanyId(companyId)) {
14704                            mbMessagePersistence.remove(mbMessage);
14705                    }
14706            }
14707    
14708            /**
14709             * Removes all the message-boards messages where threadId = &#63; from the database.
14710             *
14711             * @param threadId the thread ID
14712             * @throws SystemException if a system exception occurred
14713             */
14714            public void removeByThreadId(long threadId) throws SystemException {
14715                    for (MBMessage mbMessage : findByThreadId(threadId)) {
14716                            mbMessagePersistence.remove(mbMessage);
14717                    }
14718            }
14719    
14720            /**
14721             * Removes all the message-boards messages where threadId = &#63; from the database.
14722             *
14723             * @param threadId the thread ID
14724             * @throws SystemException if a system exception occurred
14725             */
14726            public void removeByThreadReplies(long threadId) throws SystemException {
14727                    for (MBMessage mbMessage : findByThreadReplies(threadId)) {
14728                            mbMessagePersistence.remove(mbMessage);
14729                    }
14730            }
14731    
14732            /**
14733             * Removes all the message-boards messages where userId = &#63; from the database.
14734             *
14735             * @param userId the user ID
14736             * @throws SystemException if a system exception occurred
14737             */
14738            public void removeByUserId(long userId) throws SystemException {
14739                    for (MBMessage mbMessage : findByUserId(userId)) {
14740                            mbMessagePersistence.remove(mbMessage);
14741                    }
14742            }
14743    
14744            /**
14745             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
14746             *
14747             * @param groupId the group ID
14748             * @param userId the user ID
14749             * @throws SystemException if a system exception occurred
14750             */
14751            public void removeByG_U(long groupId, long userId)
14752                    throws SystemException {
14753                    for (MBMessage mbMessage : findByG_U(groupId, userId)) {
14754                            mbMessagePersistence.remove(mbMessage);
14755                    }
14756            }
14757    
14758            /**
14759             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
14760             *
14761             * @param groupId the group ID
14762             * @param categoryId the category ID
14763             * @throws SystemException if a system exception occurred
14764             */
14765            public void removeByG_C(long groupId, long categoryId)
14766                    throws SystemException {
14767                    for (MBMessage mbMessage : findByG_C(groupId, categoryId)) {
14768                            mbMessagePersistence.remove(mbMessage);
14769                    }
14770            }
14771    
14772            /**
14773             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
14774             *
14775             * @param groupId the group ID
14776             * @param status the status
14777             * @throws SystemException if a system exception occurred
14778             */
14779            public void removeByG_S(long groupId, int status) throws SystemException {
14780                    for (MBMessage mbMessage : findByG_S(groupId, status)) {
14781                            mbMessagePersistence.remove(mbMessage);
14782                    }
14783            }
14784    
14785            /**
14786             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
14787             *
14788             * @param companyId the company ID
14789             * @param status the status
14790             * @throws SystemException if a system exception occurred
14791             */
14792            public void removeByC_S(long companyId, int status)
14793                    throws SystemException {
14794                    for (MBMessage mbMessage : findByC_S(companyId, status)) {
14795                            mbMessagePersistence.remove(mbMessage);
14796                    }
14797            }
14798    
14799            /**
14800             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
14801             *
14802             * @param userId the user ID
14803             * @param classNameId the class name ID
14804             * @throws SystemException if a system exception occurred
14805             */
14806            public void removeByU_C(long userId, long classNameId)
14807                    throws SystemException {
14808                    for (MBMessage mbMessage : findByU_C(userId, classNameId)) {
14809                            mbMessagePersistence.remove(mbMessage);
14810                    }
14811            }
14812    
14813            /**
14814             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
14815             *
14816             * @param classNameId the class name ID
14817             * @param classPK the class p k
14818             * @throws SystemException if a system exception occurred
14819             */
14820            public void removeByC_C(long classNameId, long classPK)
14821                    throws SystemException {
14822                    for (MBMessage mbMessage : findByC_C(classNameId, classPK)) {
14823                            mbMessagePersistence.remove(mbMessage);
14824                    }
14825            }
14826    
14827            /**
14828             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
14829             *
14830             * @param threadId the thread ID
14831             * @param parentMessageId the parent message ID
14832             * @throws SystemException if a system exception occurred
14833             */
14834            public void removeByT_P(long threadId, long parentMessageId)
14835                    throws SystemException {
14836                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId)) {
14837                            mbMessagePersistence.remove(mbMessage);
14838                    }
14839            }
14840    
14841            /**
14842             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
14843             *
14844             * @param threadId the thread ID
14845             * @param answer the answer
14846             * @throws SystemException if a system exception occurred
14847             */
14848            public void removeByT_A(long threadId, boolean answer)
14849                    throws SystemException {
14850                    for (MBMessage mbMessage : findByT_A(threadId, answer)) {
14851                            mbMessagePersistence.remove(mbMessage);
14852                    }
14853            }
14854    
14855            /**
14856             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
14857             *
14858             * @param threadId the thread ID
14859             * @param status the status
14860             * @throws SystemException if a system exception occurred
14861             */
14862            public void removeByT_S(long threadId, int status)
14863                    throws SystemException {
14864                    for (MBMessage mbMessage : findByT_S(threadId, status)) {
14865                            mbMessagePersistence.remove(mbMessage);
14866                    }
14867            }
14868    
14869            /**
14870             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
14871             *
14872             * @param threadId the thread ID
14873             * @param status the status
14874             * @throws SystemException if a system exception occurred
14875             */
14876            public void removeByTR_S(long threadId, int status)
14877                    throws SystemException {
14878                    for (MBMessage mbMessage : findByTR_S(threadId, status)) {
14879                            mbMessagePersistence.remove(mbMessage);
14880                    }
14881            }
14882    
14883            /**
14884             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
14885             *
14886             * @param groupId the group ID
14887             * @param userId the user ID
14888             * @param status the status
14889             * @throws SystemException if a system exception occurred
14890             */
14891            public void removeByG_U_S(long groupId, long userId, int status)
14892                    throws SystemException {
14893                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status)) {
14894                            mbMessagePersistence.remove(mbMessage);
14895                    }
14896            }
14897    
14898            /**
14899             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
14900             *
14901             * @param groupId the group ID
14902             * @param categoryId the category ID
14903             * @param threadId the thread ID
14904             * @throws SystemException if a system exception occurred
14905             */
14906            public void removeByG_C_T(long groupId, long categoryId, long threadId)
14907                    throws SystemException {
14908                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId)) {
14909                            mbMessagePersistence.remove(mbMessage);
14910                    }
14911            }
14912    
14913            /**
14914             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
14915             *
14916             * @param groupId the group ID
14917             * @param categoryId the category ID
14918             * @param status the status
14919             * @throws SystemException if a system exception occurred
14920             */
14921            public void removeByG_C_S(long groupId, long categoryId, int status)
14922                    throws SystemException {
14923                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status)) {
14924                            mbMessagePersistence.remove(mbMessage);
14925                    }
14926            }
14927    
14928            /**
14929             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
14930             *
14931             * @param userId the user ID
14932             * @param classNameId the class name ID
14933             * @param classPK the class p k
14934             * @throws SystemException if a system exception occurred
14935             */
14936            public void removeByU_C_C(long userId, long classNameId, long classPK)
14937                    throws SystemException {
14938                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK)) {
14939                            mbMessagePersistence.remove(mbMessage);
14940                    }
14941            }
14942    
14943            /**
14944             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
14945             *
14946             * @param userId the user ID
14947             * @param classNameId the class name ID
14948             * @param status the status
14949             * @throws SystemException if a system exception occurred
14950             */
14951            public void removeByU_C_S(long userId, long classNameId, int status)
14952                    throws SystemException {
14953                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status)) {
14954                            mbMessagePersistence.remove(mbMessage);
14955                    }
14956            }
14957    
14958            /**
14959             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
14960             *
14961             * @param classNameId the class name ID
14962             * @param classPK the class p k
14963             * @param status the status
14964             * @throws SystemException if a system exception occurred
14965             */
14966            public void removeByC_C_S(long classNameId, long classPK, int status)
14967                    throws SystemException {
14968                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status)) {
14969                            mbMessagePersistence.remove(mbMessage);
14970                    }
14971            }
14972    
14973            /**
14974             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
14975             *
14976             * @param groupId the group ID
14977             * @param categoryId the category ID
14978             * @param threadId the thread ID
14979             * @param answer the answer
14980             * @throws SystemException if a system exception occurred
14981             */
14982            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
14983                    boolean answer) throws SystemException {
14984                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
14985                                    answer)) {
14986                            mbMessagePersistence.remove(mbMessage);
14987                    }
14988            }
14989    
14990            /**
14991             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
14992             *
14993             * @param groupId the group ID
14994             * @param categoryId the category ID
14995             * @param threadId the thread ID
14996             * @param status the status
14997             * @throws SystemException if a system exception occurred
14998             */
14999            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
15000                    int status) throws SystemException {
15001                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
15002                                    status)) {
15003                            mbMessagePersistence.remove(mbMessage);
15004                    }
15005            }
15006    
15007            /**
15008             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
15009             *
15010             * @param userId the user ID
15011             * @param classNameId the class name ID
15012             * @param classPK the class p k
15013             * @param status the status
15014             * @throws SystemException if a system exception occurred
15015             */
15016            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
15017                    int status) throws SystemException {
15018                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
15019                                    status)) {
15020                            mbMessagePersistence.remove(mbMessage);
15021                    }
15022            }
15023    
15024            /**
15025             * Removes all the message-boards messages from the database.
15026             *
15027             * @throws SystemException if a system exception occurred
15028             */
15029            public void removeAll() throws SystemException {
15030                    for (MBMessage mbMessage : findAll()) {
15031                            mbMessagePersistence.remove(mbMessage);
15032                    }
15033            }
15034    
15035            /**
15036             * Returns the number of message-boards messages where uuid = &#63;.
15037             *
15038             * @param uuid the uuid
15039             * @return the number of matching message-boards messages
15040             * @throws SystemException if a system exception occurred
15041             */
15042            public int countByUuid(String uuid) throws SystemException {
15043                    Object[] finderArgs = new Object[] { uuid };
15044    
15045                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
15046                                    finderArgs, this);
15047    
15048                    if (count == null) {
15049                            StringBundler query = new StringBundler(2);
15050    
15051                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15052    
15053                            if (uuid == null) {
15054                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
15055                            }
15056                            else {
15057                                    if (uuid.equals(StringPool.BLANK)) {
15058                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
15059                                    }
15060                                    else {
15061                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
15062                                    }
15063                            }
15064    
15065                            String sql = query.toString();
15066    
15067                            Session session = null;
15068    
15069                            try {
15070                                    session = openSession();
15071    
15072                                    Query q = session.createQuery(sql);
15073    
15074                                    QueryPos qPos = QueryPos.getInstance(q);
15075    
15076                                    if (uuid != null) {
15077                                            qPos.add(uuid);
15078                                    }
15079    
15080                                    count = (Long)q.uniqueResult();
15081                            }
15082                            catch (Exception e) {
15083                                    throw processException(e);
15084                            }
15085                            finally {
15086                                    if (count == null) {
15087                                            count = Long.valueOf(0);
15088                                    }
15089    
15090                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
15091                                            finderArgs, count);
15092    
15093                                    closeSession(session);
15094                            }
15095                    }
15096    
15097                    return count.intValue();
15098            }
15099    
15100            /**
15101             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
15102             *
15103             * @param uuid the uuid
15104             * @param groupId the group ID
15105             * @return the number of matching message-boards messages
15106             * @throws SystemException if a system exception occurred
15107             */
15108            public int countByUUID_G(String uuid, long groupId)
15109                    throws SystemException {
15110                    Object[] finderArgs = new Object[] { uuid, groupId };
15111    
15112                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
15113                                    finderArgs, this);
15114    
15115                    if (count == null) {
15116                            StringBundler query = new StringBundler(3);
15117    
15118                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15119    
15120                            if (uuid == null) {
15121                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
15122                            }
15123                            else {
15124                                    if (uuid.equals(StringPool.BLANK)) {
15125                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
15126                                    }
15127                                    else {
15128                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
15129                                    }
15130                            }
15131    
15132                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
15133    
15134                            String sql = query.toString();
15135    
15136                            Session session = null;
15137    
15138                            try {
15139                                    session = openSession();
15140    
15141                                    Query q = session.createQuery(sql);
15142    
15143                                    QueryPos qPos = QueryPos.getInstance(q);
15144    
15145                                    if (uuid != null) {
15146                                            qPos.add(uuid);
15147                                    }
15148    
15149                                    qPos.add(groupId);
15150    
15151                                    count = (Long)q.uniqueResult();
15152                            }
15153                            catch (Exception e) {
15154                                    throw processException(e);
15155                            }
15156                            finally {
15157                                    if (count == null) {
15158                                            count = Long.valueOf(0);
15159                                    }
15160    
15161                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
15162                                            finderArgs, count);
15163    
15164                                    closeSession(session);
15165                            }
15166                    }
15167    
15168                    return count.intValue();
15169            }
15170    
15171            /**
15172             * Returns the number of message-boards messages where groupId = &#63;.
15173             *
15174             * @param groupId the group ID
15175             * @return the number of matching message-boards messages
15176             * @throws SystemException if a system exception occurred
15177             */
15178            public int countByGroupId(long groupId) throws SystemException {
15179                    Object[] finderArgs = new Object[] { groupId };
15180    
15181                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
15182                                    finderArgs, this);
15183    
15184                    if (count == null) {
15185                            StringBundler query = new StringBundler(2);
15186    
15187                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15188    
15189                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
15190    
15191                            String sql = query.toString();
15192    
15193                            Session session = null;
15194    
15195                            try {
15196                                    session = openSession();
15197    
15198                                    Query q = session.createQuery(sql);
15199    
15200                                    QueryPos qPos = QueryPos.getInstance(q);
15201    
15202                                    qPos.add(groupId);
15203    
15204                                    count = (Long)q.uniqueResult();
15205                            }
15206                            catch (Exception e) {
15207                                    throw processException(e);
15208                            }
15209                            finally {
15210                                    if (count == null) {
15211                                            count = Long.valueOf(0);
15212                                    }
15213    
15214                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
15215                                            finderArgs, count);
15216    
15217                                    closeSession(session);
15218                            }
15219                    }
15220    
15221                    return count.intValue();
15222            }
15223    
15224            /**
15225             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
15226             *
15227             * @param groupId the group ID
15228             * @return the number of matching message-boards messages that the user has permission to view
15229             * @throws SystemException if a system exception occurred
15230             */
15231            public int filterCountByGroupId(long groupId) throws SystemException {
15232                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15233                            return countByGroupId(groupId);
15234                    }
15235    
15236                    StringBundler query = new StringBundler(2);
15237    
15238                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
15239    
15240                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
15241    
15242                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15243                                    MBMessage.class.getName(),
15244                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15245    
15246                    Session session = null;
15247    
15248                    try {
15249                            session = openSession();
15250    
15251                            SQLQuery q = session.createSQLQuery(sql);
15252    
15253                            q.addScalar(COUNT_COLUMN_NAME,
15254                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
15255    
15256                            QueryPos qPos = QueryPos.getInstance(q);
15257    
15258                            qPos.add(groupId);
15259    
15260                            Long count = (Long)q.uniqueResult();
15261    
15262                            return count.intValue();
15263                    }
15264                    catch (Exception e) {
15265                            throw processException(e);
15266                    }
15267                    finally {
15268                            closeSession(session);
15269                    }
15270            }
15271    
15272            /**
15273             * Returns the number of message-boards messages where companyId = &#63;.
15274             *
15275             * @param companyId the company ID
15276             * @return the number of matching message-boards messages
15277             * @throws SystemException if a system exception occurred
15278             */
15279            public int countByCompanyId(long companyId) throws SystemException {
15280                    Object[] finderArgs = new Object[] { companyId };
15281    
15282                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
15283                                    finderArgs, this);
15284    
15285                    if (count == null) {
15286                            StringBundler query = new StringBundler(2);
15287    
15288                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15289    
15290                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
15291    
15292                            String sql = query.toString();
15293    
15294                            Session session = null;
15295    
15296                            try {
15297                                    session = openSession();
15298    
15299                                    Query q = session.createQuery(sql);
15300    
15301                                    QueryPos qPos = QueryPos.getInstance(q);
15302    
15303                                    qPos.add(companyId);
15304    
15305                                    count = (Long)q.uniqueResult();
15306                            }
15307                            catch (Exception e) {
15308                                    throw processException(e);
15309                            }
15310                            finally {
15311                                    if (count == null) {
15312                                            count = Long.valueOf(0);
15313                                    }
15314    
15315                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
15316                                            finderArgs, count);
15317    
15318                                    closeSession(session);
15319                            }
15320                    }
15321    
15322                    return count.intValue();
15323            }
15324    
15325            /**
15326             * Returns the number of message-boards messages where threadId = &#63;.
15327             *
15328             * @param threadId the thread ID
15329             * @return the number of matching message-boards messages
15330             * @throws SystemException if a system exception occurred
15331             */
15332            public int countByThreadId(long threadId) throws SystemException {
15333                    Object[] finderArgs = new Object[] { threadId };
15334    
15335                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
15336                                    finderArgs, this);
15337    
15338                    if (count == null) {
15339                            StringBundler query = new StringBundler(2);
15340    
15341                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15342    
15343                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
15344    
15345                            String sql = query.toString();
15346    
15347                            Session session = null;
15348    
15349                            try {
15350                                    session = openSession();
15351    
15352                                    Query q = session.createQuery(sql);
15353    
15354                                    QueryPos qPos = QueryPos.getInstance(q);
15355    
15356                                    qPos.add(threadId);
15357    
15358                                    count = (Long)q.uniqueResult();
15359                            }
15360                            catch (Exception e) {
15361                                    throw processException(e);
15362                            }
15363                            finally {
15364                                    if (count == null) {
15365                                            count = Long.valueOf(0);
15366                                    }
15367    
15368                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
15369                                            finderArgs, count);
15370    
15371                                    closeSession(session);
15372                            }
15373                    }
15374    
15375                    return count.intValue();
15376            }
15377    
15378            /**
15379             * Returns the number of message-boards messages where threadId = &#63;.
15380             *
15381             * @param threadId the thread ID
15382             * @return the number of matching message-boards messages
15383             * @throws SystemException if a system exception occurred
15384             */
15385            public int countByThreadReplies(long threadId) throws SystemException {
15386                    Object[] finderArgs = new Object[] { threadId };
15387    
15388                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
15389                                    finderArgs, this);
15390    
15391                    if (count == null) {
15392                            StringBundler query = new StringBundler(2);
15393    
15394                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15395    
15396                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
15397    
15398                            String sql = query.toString();
15399    
15400                            Session session = null;
15401    
15402                            try {
15403                                    session = openSession();
15404    
15405                                    Query q = session.createQuery(sql);
15406    
15407                                    QueryPos qPos = QueryPos.getInstance(q);
15408    
15409                                    qPos.add(threadId);
15410    
15411                                    count = (Long)q.uniqueResult();
15412                            }
15413                            catch (Exception e) {
15414                                    throw processException(e);
15415                            }
15416                            finally {
15417                                    if (count == null) {
15418                                            count = Long.valueOf(0);
15419                                    }
15420    
15421                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
15422                                            finderArgs, count);
15423    
15424                                    closeSession(session);
15425                            }
15426                    }
15427    
15428                    return count.intValue();
15429            }
15430    
15431            /**
15432             * Returns the number of message-boards messages where userId = &#63;.
15433             *
15434             * @param userId the user ID
15435             * @return the number of matching message-boards messages
15436             * @throws SystemException if a system exception occurred
15437             */
15438            public int countByUserId(long userId) throws SystemException {
15439                    Object[] finderArgs = new Object[] { userId };
15440    
15441                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
15442                                    finderArgs, this);
15443    
15444                    if (count == null) {
15445                            StringBundler query = new StringBundler(2);
15446    
15447                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15448    
15449                            query.append(_FINDER_COLUMN_USERID_USERID_2);
15450    
15451                            String sql = query.toString();
15452    
15453                            Session session = null;
15454    
15455                            try {
15456                                    session = openSession();
15457    
15458                                    Query q = session.createQuery(sql);
15459    
15460                                    QueryPos qPos = QueryPos.getInstance(q);
15461    
15462                                    qPos.add(userId);
15463    
15464                                    count = (Long)q.uniqueResult();
15465                            }
15466                            catch (Exception e) {
15467                                    throw processException(e);
15468                            }
15469                            finally {
15470                                    if (count == null) {
15471                                            count = Long.valueOf(0);
15472                                    }
15473    
15474                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
15475                                            finderArgs, count);
15476    
15477                                    closeSession(session);
15478                            }
15479                    }
15480    
15481                    return count.intValue();
15482            }
15483    
15484            /**
15485             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
15486             *
15487             * @param groupId the group ID
15488             * @param userId the user ID
15489             * @return the number of matching message-boards messages
15490             * @throws SystemException if a system exception occurred
15491             */
15492            public int countByG_U(long groupId, long userId) throws SystemException {
15493                    Object[] finderArgs = new Object[] { groupId, userId };
15494    
15495                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
15496                                    finderArgs, this);
15497    
15498                    if (count == null) {
15499                            StringBundler query = new StringBundler(3);
15500    
15501                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15502    
15503                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
15504    
15505                            query.append(_FINDER_COLUMN_G_U_USERID_2);
15506    
15507                            String sql = query.toString();
15508    
15509                            Session session = null;
15510    
15511                            try {
15512                                    session = openSession();
15513    
15514                                    Query q = session.createQuery(sql);
15515    
15516                                    QueryPos qPos = QueryPos.getInstance(q);
15517    
15518                                    qPos.add(groupId);
15519    
15520                                    qPos.add(userId);
15521    
15522                                    count = (Long)q.uniqueResult();
15523                            }
15524                            catch (Exception e) {
15525                                    throw processException(e);
15526                            }
15527                            finally {
15528                                    if (count == null) {
15529                                            count = Long.valueOf(0);
15530                                    }
15531    
15532                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
15533                                            count);
15534    
15535                                    closeSession(session);
15536                            }
15537                    }
15538    
15539                    return count.intValue();
15540            }
15541    
15542            /**
15543             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
15544             *
15545             * @param groupId the group ID
15546             * @param userId the user ID
15547             * @return the number of matching message-boards messages that the user has permission to view
15548             * @throws SystemException if a system exception occurred
15549             */
15550            public int filterCountByG_U(long groupId, long userId)
15551                    throws SystemException {
15552                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15553                            return countByG_U(groupId, userId);
15554                    }
15555    
15556                    StringBundler query = new StringBundler(3);
15557    
15558                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
15559    
15560                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
15561    
15562                    query.append(_FINDER_COLUMN_G_U_USERID_2);
15563    
15564                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15565                                    MBMessage.class.getName(),
15566                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15567    
15568                    Session session = null;
15569    
15570                    try {
15571                            session = openSession();
15572    
15573                            SQLQuery q = session.createSQLQuery(sql);
15574    
15575                            q.addScalar(COUNT_COLUMN_NAME,
15576                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
15577    
15578                            QueryPos qPos = QueryPos.getInstance(q);
15579    
15580                            qPos.add(groupId);
15581    
15582                            qPos.add(userId);
15583    
15584                            Long count = (Long)q.uniqueResult();
15585    
15586                            return count.intValue();
15587                    }
15588                    catch (Exception e) {
15589                            throw processException(e);
15590                    }
15591                    finally {
15592                            closeSession(session);
15593                    }
15594            }
15595    
15596            /**
15597             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
15598             *
15599             * @param groupId the group ID
15600             * @param categoryId the category ID
15601             * @return the number of matching message-boards messages
15602             * @throws SystemException if a system exception occurred
15603             */
15604            public int countByG_C(long groupId, long categoryId)
15605                    throws SystemException {
15606                    Object[] finderArgs = new Object[] { groupId, categoryId };
15607    
15608                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
15609                                    finderArgs, this);
15610    
15611                    if (count == null) {
15612                            StringBundler query = new StringBundler(3);
15613    
15614                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15615    
15616                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
15617    
15618                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
15619    
15620                            String sql = query.toString();
15621    
15622                            Session session = null;
15623    
15624                            try {
15625                                    session = openSession();
15626    
15627                                    Query q = session.createQuery(sql);
15628    
15629                                    QueryPos qPos = QueryPos.getInstance(q);
15630    
15631                                    qPos.add(groupId);
15632    
15633                                    qPos.add(categoryId);
15634    
15635                                    count = (Long)q.uniqueResult();
15636                            }
15637                            catch (Exception e) {
15638                                    throw processException(e);
15639                            }
15640                            finally {
15641                                    if (count == null) {
15642                                            count = Long.valueOf(0);
15643                                    }
15644    
15645                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
15646                                            count);
15647    
15648                                    closeSession(session);
15649                            }
15650                    }
15651    
15652                    return count.intValue();
15653            }
15654    
15655            /**
15656             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
15657             *
15658             * @param groupId the group ID
15659             * @param categoryId the category ID
15660             * @return the number of matching message-boards messages that the user has permission to view
15661             * @throws SystemException if a system exception occurred
15662             */
15663            public int filterCountByG_C(long groupId, long categoryId)
15664                    throws SystemException {
15665                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15666                            return countByG_C(groupId, categoryId);
15667                    }
15668    
15669                    StringBundler query = new StringBundler(3);
15670    
15671                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
15672    
15673                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
15674    
15675                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
15676    
15677                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15678                                    MBMessage.class.getName(),
15679                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15680    
15681                    Session session = null;
15682    
15683                    try {
15684                            session = openSession();
15685    
15686                            SQLQuery q = session.createSQLQuery(sql);
15687    
15688                            q.addScalar(COUNT_COLUMN_NAME,
15689                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
15690    
15691                            QueryPos qPos = QueryPos.getInstance(q);
15692    
15693                            qPos.add(groupId);
15694    
15695                            qPos.add(categoryId);
15696    
15697                            Long count = (Long)q.uniqueResult();
15698    
15699                            return count.intValue();
15700                    }
15701                    catch (Exception e) {
15702                            throw processException(e);
15703                    }
15704                    finally {
15705                            closeSession(session);
15706                    }
15707            }
15708    
15709            /**
15710             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
15711             *
15712             * @param groupId the group ID
15713             * @param status the status
15714             * @return the number of matching message-boards messages
15715             * @throws SystemException if a system exception occurred
15716             */
15717            public int countByG_S(long groupId, int status) throws SystemException {
15718                    Object[] finderArgs = new Object[] { groupId, status };
15719    
15720                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
15721                                    finderArgs, this);
15722    
15723                    if (count == null) {
15724                            StringBundler query = new StringBundler(3);
15725    
15726                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15727    
15728                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
15729    
15730                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
15731    
15732                            String sql = query.toString();
15733    
15734                            Session session = null;
15735    
15736                            try {
15737                                    session = openSession();
15738    
15739                                    Query q = session.createQuery(sql);
15740    
15741                                    QueryPos qPos = QueryPos.getInstance(q);
15742    
15743                                    qPos.add(groupId);
15744    
15745                                    qPos.add(status);
15746    
15747                                    count = (Long)q.uniqueResult();
15748                            }
15749                            catch (Exception e) {
15750                                    throw processException(e);
15751                            }
15752                            finally {
15753                                    if (count == null) {
15754                                            count = Long.valueOf(0);
15755                                    }
15756    
15757                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
15758                                            count);
15759    
15760                                    closeSession(session);
15761                            }
15762                    }
15763    
15764                    return count.intValue();
15765            }
15766    
15767            /**
15768             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
15769             *
15770             * @param groupId the group ID
15771             * @param status the status
15772             * @return the number of matching message-boards messages that the user has permission to view
15773             * @throws SystemException if a system exception occurred
15774             */
15775            public int filterCountByG_S(long groupId, int status)
15776                    throws SystemException {
15777                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15778                            return countByG_S(groupId, status);
15779                    }
15780    
15781                    StringBundler query = new StringBundler(3);
15782    
15783                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
15784    
15785                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
15786    
15787                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
15788    
15789                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15790                                    MBMessage.class.getName(),
15791                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15792    
15793                    Session session = null;
15794    
15795                    try {
15796                            session = openSession();
15797    
15798                            SQLQuery q = session.createSQLQuery(sql);
15799    
15800                            q.addScalar(COUNT_COLUMN_NAME,
15801                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
15802    
15803                            QueryPos qPos = QueryPos.getInstance(q);
15804    
15805                            qPos.add(groupId);
15806    
15807                            qPos.add(status);
15808    
15809                            Long count = (Long)q.uniqueResult();
15810    
15811                            return count.intValue();
15812                    }
15813                    catch (Exception e) {
15814                            throw processException(e);
15815                    }
15816                    finally {
15817                            closeSession(session);
15818                    }
15819            }
15820    
15821            /**
15822             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
15823             *
15824             * @param companyId the company ID
15825             * @param status the status
15826             * @return the number of matching message-boards messages
15827             * @throws SystemException if a system exception occurred
15828             */
15829            public int countByC_S(long companyId, int status) throws SystemException {
15830                    Object[] finderArgs = new Object[] { companyId, status };
15831    
15832                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_S,
15833                                    finderArgs, this);
15834    
15835                    if (count == null) {
15836                            StringBundler query = new StringBundler(3);
15837    
15838                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15839    
15840                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
15841    
15842                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
15843    
15844                            String sql = query.toString();
15845    
15846                            Session session = null;
15847    
15848                            try {
15849                                    session = openSession();
15850    
15851                                    Query q = session.createQuery(sql);
15852    
15853                                    QueryPos qPos = QueryPos.getInstance(q);
15854    
15855                                    qPos.add(companyId);
15856    
15857                                    qPos.add(status);
15858    
15859                                    count = (Long)q.uniqueResult();
15860                            }
15861                            catch (Exception e) {
15862                                    throw processException(e);
15863                            }
15864                            finally {
15865                                    if (count == null) {
15866                                            count = Long.valueOf(0);
15867                                    }
15868    
15869                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_S, finderArgs,
15870                                            count);
15871    
15872                                    closeSession(session);
15873                            }
15874                    }
15875    
15876                    return count.intValue();
15877            }
15878    
15879            /**
15880             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
15881             *
15882             * @param userId the user ID
15883             * @param classNameId the class name ID
15884             * @return the number of matching message-boards messages
15885             * @throws SystemException if a system exception occurred
15886             */
15887            public int countByU_C(long userId, long classNameId)
15888                    throws SystemException {
15889                    Object[] finderArgs = new Object[] { userId, classNameId };
15890    
15891                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C,
15892                                    finderArgs, this);
15893    
15894                    if (count == null) {
15895                            StringBundler query = new StringBundler(3);
15896    
15897                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15898    
15899                            query.append(_FINDER_COLUMN_U_C_USERID_2);
15900    
15901                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
15902    
15903                            String sql = query.toString();
15904    
15905                            Session session = null;
15906    
15907                            try {
15908                                    session = openSession();
15909    
15910                                    Query q = session.createQuery(sql);
15911    
15912                                    QueryPos qPos = QueryPos.getInstance(q);
15913    
15914                                    qPos.add(userId);
15915    
15916                                    qPos.add(classNameId);
15917    
15918                                    count = (Long)q.uniqueResult();
15919                            }
15920                            catch (Exception e) {
15921                                    throw processException(e);
15922                            }
15923                            finally {
15924                                    if (count == null) {
15925                                            count = Long.valueOf(0);
15926                                    }
15927    
15928                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C, finderArgs,
15929                                            count);
15930    
15931                                    closeSession(session);
15932                            }
15933                    }
15934    
15935                    return count.intValue();
15936            }
15937    
15938            /**
15939             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
15940             *
15941             * @param userId the user ID
15942             * @param classNameIds the class name IDs
15943             * @return the number of matching message-boards messages
15944             * @throws SystemException if a system exception occurred
15945             */
15946            public int countByU_C(long userId, long[] classNameIds)
15947                    throws SystemException {
15948                    Object[] finderArgs = new Object[] {
15949                                    userId, StringUtil.merge(classNameIds)
15950                            };
15951    
15952                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C,
15953                                    finderArgs, this);
15954    
15955                    if (count == null) {
15956                            StringBundler query = new StringBundler();
15957    
15958                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15959    
15960                            boolean conjunctionable = false;
15961    
15962                            if (conjunctionable) {
15963                                    query.append(WHERE_AND);
15964                            }
15965    
15966                            query.append(_FINDER_COLUMN_U_C_USERID_5);
15967    
15968                            conjunctionable = true;
15969    
15970                            if ((classNameIds == null) || (classNameIds.length > 0)) {
15971                                    if (conjunctionable) {
15972                                            query.append(WHERE_AND);
15973                                    }
15974    
15975                                    query.append(StringPool.OPEN_PARENTHESIS);
15976    
15977                                    for (int i = 0; i < classNameIds.length; i++) {
15978                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
15979    
15980                                            if ((i + 1) < classNameIds.length) {
15981                                                    query.append(WHERE_OR);
15982                                            }
15983                                    }
15984    
15985                                    query.append(StringPool.CLOSE_PARENTHESIS);
15986    
15987                                    conjunctionable = true;
15988                            }
15989    
15990                            String sql = query.toString();
15991    
15992                            Session session = null;
15993    
15994                            try {
15995                                    session = openSession();
15996    
15997                                    Query q = session.createQuery(sql);
15998    
15999                                    QueryPos qPos = QueryPos.getInstance(q);
16000    
16001                                    qPos.add(userId);
16002    
16003                                    if (classNameIds != null) {
16004                                            qPos.add(classNameIds);
16005                                    }
16006    
16007                                    count = (Long)q.uniqueResult();
16008                            }
16009                            catch (Exception e) {
16010                                    throw processException(e);
16011                            }
16012                            finally {
16013                                    if (count == null) {
16014                                            count = Long.valueOf(0);
16015                                    }
16016    
16017                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C, finderArgs,
16018                                            count);
16019    
16020                                    closeSession(session);
16021                            }
16022                    }
16023    
16024                    return count.intValue();
16025            }
16026    
16027            /**
16028             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
16029             *
16030             * @param classNameId the class name ID
16031             * @param classPK the class p k
16032             * @return the number of matching message-boards messages
16033             * @throws SystemException if a system exception occurred
16034             */
16035            public int countByC_C(long classNameId, long classPK)
16036                    throws SystemException {
16037                    Object[] finderArgs = new Object[] { classNameId, classPK };
16038    
16039                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
16040                                    finderArgs, this);
16041    
16042                    if (count == null) {
16043                            StringBundler query = new StringBundler(3);
16044    
16045                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16046    
16047                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
16048    
16049                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
16050    
16051                            String sql = query.toString();
16052    
16053                            Session session = null;
16054    
16055                            try {
16056                                    session = openSession();
16057    
16058                                    Query q = session.createQuery(sql);
16059    
16060                                    QueryPos qPos = QueryPos.getInstance(q);
16061    
16062                                    qPos.add(classNameId);
16063    
16064                                    qPos.add(classPK);
16065    
16066                                    count = (Long)q.uniqueResult();
16067                            }
16068                            catch (Exception e) {
16069                                    throw processException(e);
16070                            }
16071                            finally {
16072                                    if (count == null) {
16073                                            count = Long.valueOf(0);
16074                                    }
16075    
16076                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
16077                                            count);
16078    
16079                                    closeSession(session);
16080                            }
16081                    }
16082    
16083                    return count.intValue();
16084            }
16085    
16086            /**
16087             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
16088             *
16089             * @param threadId the thread ID
16090             * @param parentMessageId the parent message ID
16091             * @return the number of matching message-boards messages
16092             * @throws SystemException if a system exception occurred
16093             */
16094            public int countByT_P(long threadId, long parentMessageId)
16095                    throws SystemException {
16096                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
16097    
16098                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_P,
16099                                    finderArgs, this);
16100    
16101                    if (count == null) {
16102                            StringBundler query = new StringBundler(3);
16103    
16104                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16105    
16106                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
16107    
16108                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
16109    
16110                            String sql = query.toString();
16111    
16112                            Session session = null;
16113    
16114                            try {
16115                                    session = openSession();
16116    
16117                                    Query q = session.createQuery(sql);
16118    
16119                                    QueryPos qPos = QueryPos.getInstance(q);
16120    
16121                                    qPos.add(threadId);
16122    
16123                                    qPos.add(parentMessageId);
16124    
16125                                    count = (Long)q.uniqueResult();
16126                            }
16127                            catch (Exception e) {
16128                                    throw processException(e);
16129                            }
16130                            finally {
16131                                    if (count == null) {
16132                                            count = Long.valueOf(0);
16133                                    }
16134    
16135                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_P, finderArgs,
16136                                            count);
16137    
16138                                    closeSession(session);
16139                            }
16140                    }
16141    
16142                    return count.intValue();
16143            }
16144    
16145            /**
16146             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
16147             *
16148             * @param threadId the thread ID
16149             * @param answer the answer
16150             * @return the number of matching message-boards messages
16151             * @throws SystemException if a system exception occurred
16152             */
16153            public int countByT_A(long threadId, boolean answer)
16154                    throws SystemException {
16155                    Object[] finderArgs = new Object[] { threadId, answer };
16156    
16157                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_A,
16158                                    finderArgs, this);
16159    
16160                    if (count == null) {
16161                            StringBundler query = new StringBundler(3);
16162    
16163                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16164    
16165                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
16166    
16167                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
16168    
16169                            String sql = query.toString();
16170    
16171                            Session session = null;
16172    
16173                            try {
16174                                    session = openSession();
16175    
16176                                    Query q = session.createQuery(sql);
16177    
16178                                    QueryPos qPos = QueryPos.getInstance(q);
16179    
16180                                    qPos.add(threadId);
16181    
16182                                    qPos.add(answer);
16183    
16184                                    count = (Long)q.uniqueResult();
16185                            }
16186                            catch (Exception e) {
16187                                    throw processException(e);
16188                            }
16189                            finally {
16190                                    if (count == null) {
16191                                            count = Long.valueOf(0);
16192                                    }
16193    
16194                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_A, finderArgs,
16195                                            count);
16196    
16197                                    closeSession(session);
16198                            }
16199                    }
16200    
16201                    return count.intValue();
16202            }
16203    
16204            /**
16205             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
16206             *
16207             * @param threadId the thread ID
16208             * @param status the status
16209             * @return the number of matching message-boards messages
16210             * @throws SystemException if a system exception occurred
16211             */
16212            public int countByT_S(long threadId, int status) throws SystemException {
16213                    Object[] finderArgs = new Object[] { threadId, status };
16214    
16215                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_S,
16216                                    finderArgs, this);
16217    
16218                    if (count == null) {
16219                            StringBundler query = new StringBundler(3);
16220    
16221                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16222    
16223                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
16224    
16225                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
16226    
16227                            String sql = query.toString();
16228    
16229                            Session session = null;
16230    
16231                            try {
16232                                    session = openSession();
16233    
16234                                    Query q = session.createQuery(sql);
16235    
16236                                    QueryPos qPos = QueryPos.getInstance(q);
16237    
16238                                    qPos.add(threadId);
16239    
16240                                    qPos.add(status);
16241    
16242                                    count = (Long)q.uniqueResult();
16243                            }
16244                            catch (Exception e) {
16245                                    throw processException(e);
16246                            }
16247                            finally {
16248                                    if (count == null) {
16249                                            count = Long.valueOf(0);
16250                                    }
16251    
16252                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_S, finderArgs,
16253                                            count);
16254    
16255                                    closeSession(session);
16256                            }
16257                    }
16258    
16259                    return count.intValue();
16260            }
16261    
16262            /**
16263             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
16264             *
16265             * @param threadId the thread ID
16266             * @param status the status
16267             * @return the number of matching message-boards messages
16268             * @throws SystemException if a system exception occurred
16269             */
16270            public int countByTR_S(long threadId, int status) throws SystemException {
16271                    Object[] finderArgs = new Object[] { threadId, status };
16272    
16273                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TR_S,
16274                                    finderArgs, this);
16275    
16276                    if (count == null) {
16277                            StringBundler query = new StringBundler(3);
16278    
16279                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16280    
16281                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
16282    
16283                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
16284    
16285                            String sql = query.toString();
16286    
16287                            Session session = null;
16288    
16289                            try {
16290                                    session = openSession();
16291    
16292                                    Query q = session.createQuery(sql);
16293    
16294                                    QueryPos qPos = QueryPos.getInstance(q);
16295    
16296                                    qPos.add(threadId);
16297    
16298                                    qPos.add(status);
16299    
16300                                    count = (Long)q.uniqueResult();
16301                            }
16302                            catch (Exception e) {
16303                                    throw processException(e);
16304                            }
16305                            finally {
16306                                    if (count == null) {
16307                                            count = Long.valueOf(0);
16308                                    }
16309    
16310                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TR_S,
16311                                            finderArgs, count);
16312    
16313                                    closeSession(session);
16314                            }
16315                    }
16316    
16317                    return count.intValue();
16318            }
16319    
16320            /**
16321             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
16322             *
16323             * @param groupId the group ID
16324             * @param userId the user ID
16325             * @param status the status
16326             * @return the number of matching message-boards messages
16327             * @throws SystemException if a system exception occurred
16328             */
16329            public int countByG_U_S(long groupId, long userId, int status)
16330                    throws SystemException {
16331                    Object[] finderArgs = new Object[] { groupId, userId, status };
16332    
16333                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_S,
16334                                    finderArgs, this);
16335    
16336                    if (count == null) {
16337                            StringBundler query = new StringBundler(4);
16338    
16339                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16340    
16341                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
16342    
16343                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
16344    
16345                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
16346    
16347                            String sql = query.toString();
16348    
16349                            Session session = null;
16350    
16351                            try {
16352                                    session = openSession();
16353    
16354                                    Query q = session.createQuery(sql);
16355    
16356                                    QueryPos qPos = QueryPos.getInstance(q);
16357    
16358                                    qPos.add(groupId);
16359    
16360                                    qPos.add(userId);
16361    
16362                                    qPos.add(status);
16363    
16364                                    count = (Long)q.uniqueResult();
16365                            }
16366                            catch (Exception e) {
16367                                    throw processException(e);
16368                            }
16369                            finally {
16370                                    if (count == null) {
16371                                            count = Long.valueOf(0);
16372                                    }
16373    
16374                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_S,
16375                                            finderArgs, count);
16376    
16377                                    closeSession(session);
16378                            }
16379                    }
16380    
16381                    return count.intValue();
16382            }
16383    
16384            /**
16385             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
16386             *
16387             * @param groupId the group ID
16388             * @param userId the user ID
16389             * @param status the status
16390             * @return the number of matching message-boards messages that the user has permission to view
16391             * @throws SystemException if a system exception occurred
16392             */
16393            public int filterCountByG_U_S(long groupId, long userId, int status)
16394                    throws SystemException {
16395                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16396                            return countByG_U_S(groupId, userId, status);
16397                    }
16398    
16399                    StringBundler query = new StringBundler(4);
16400    
16401                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16402    
16403                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
16404    
16405                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
16406    
16407                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
16408    
16409                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16410                                    MBMessage.class.getName(),
16411                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16412    
16413                    Session session = null;
16414    
16415                    try {
16416                            session = openSession();
16417    
16418                            SQLQuery q = session.createSQLQuery(sql);
16419    
16420                            q.addScalar(COUNT_COLUMN_NAME,
16421                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16422    
16423                            QueryPos qPos = QueryPos.getInstance(q);
16424    
16425                            qPos.add(groupId);
16426    
16427                            qPos.add(userId);
16428    
16429                            qPos.add(status);
16430    
16431                            Long count = (Long)q.uniqueResult();
16432    
16433                            return count.intValue();
16434                    }
16435                    catch (Exception e) {
16436                            throw processException(e);
16437                    }
16438                    finally {
16439                            closeSession(session);
16440                    }
16441            }
16442    
16443            /**
16444             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
16445             *
16446             * @param groupId the group ID
16447             * @param categoryId the category ID
16448             * @param threadId the thread ID
16449             * @return the number of matching message-boards messages
16450             * @throws SystemException if a system exception occurred
16451             */
16452            public int countByG_C_T(long groupId, long categoryId, long threadId)
16453                    throws SystemException {
16454                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
16455    
16456                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T,
16457                                    finderArgs, this);
16458    
16459                    if (count == null) {
16460                            StringBundler query = new StringBundler(4);
16461    
16462                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16463    
16464                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
16465    
16466                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
16467    
16468                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
16469    
16470                            String sql = query.toString();
16471    
16472                            Session session = null;
16473    
16474                            try {
16475                                    session = openSession();
16476    
16477                                    Query q = session.createQuery(sql);
16478    
16479                                    QueryPos qPos = QueryPos.getInstance(q);
16480    
16481                                    qPos.add(groupId);
16482    
16483                                    qPos.add(categoryId);
16484    
16485                                    qPos.add(threadId);
16486    
16487                                    count = (Long)q.uniqueResult();
16488                            }
16489                            catch (Exception e) {
16490                                    throw processException(e);
16491                            }
16492                            finally {
16493                                    if (count == null) {
16494                                            count = Long.valueOf(0);
16495                                    }
16496    
16497                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T,
16498                                            finderArgs, count);
16499    
16500                                    closeSession(session);
16501                            }
16502                    }
16503    
16504                    return count.intValue();
16505            }
16506    
16507            /**
16508             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
16509             *
16510             * @param groupId the group ID
16511             * @param categoryId the category ID
16512             * @param threadId the thread ID
16513             * @return the number of matching message-boards messages that the user has permission to view
16514             * @throws SystemException if a system exception occurred
16515             */
16516            public int filterCountByG_C_T(long groupId, long categoryId, long threadId)
16517                    throws SystemException {
16518                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16519                            return countByG_C_T(groupId, categoryId, threadId);
16520                    }
16521    
16522                    StringBundler query = new StringBundler(4);
16523    
16524                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16525    
16526                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
16527    
16528                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
16529    
16530                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
16531    
16532                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16533                                    MBMessage.class.getName(),
16534                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16535    
16536                    Session session = null;
16537    
16538                    try {
16539                            session = openSession();
16540    
16541                            SQLQuery q = session.createSQLQuery(sql);
16542    
16543                            q.addScalar(COUNT_COLUMN_NAME,
16544                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16545    
16546                            QueryPos qPos = QueryPos.getInstance(q);
16547    
16548                            qPos.add(groupId);
16549    
16550                            qPos.add(categoryId);
16551    
16552                            qPos.add(threadId);
16553    
16554                            Long count = (Long)q.uniqueResult();
16555    
16556                            return count.intValue();
16557                    }
16558                    catch (Exception e) {
16559                            throw processException(e);
16560                    }
16561                    finally {
16562                            closeSession(session);
16563                    }
16564            }
16565    
16566            /**
16567             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
16568             *
16569             * @param groupId the group ID
16570             * @param categoryId the category ID
16571             * @param status the status
16572             * @return the number of matching message-boards messages
16573             * @throws SystemException if a system exception occurred
16574             */
16575            public int countByG_C_S(long groupId, long categoryId, int status)
16576                    throws SystemException {
16577                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
16578    
16579                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_S,
16580                                    finderArgs, this);
16581    
16582                    if (count == null) {
16583                            StringBundler query = new StringBundler(4);
16584    
16585                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16586    
16587                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
16588    
16589                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
16590    
16591                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
16592    
16593                            String sql = query.toString();
16594    
16595                            Session session = null;
16596    
16597                            try {
16598                                    session = openSession();
16599    
16600                                    Query q = session.createQuery(sql);
16601    
16602                                    QueryPos qPos = QueryPos.getInstance(q);
16603    
16604                                    qPos.add(groupId);
16605    
16606                                    qPos.add(categoryId);
16607    
16608                                    qPos.add(status);
16609    
16610                                    count = (Long)q.uniqueResult();
16611                            }
16612                            catch (Exception e) {
16613                                    throw processException(e);
16614                            }
16615                            finally {
16616                                    if (count == null) {
16617                                            count = Long.valueOf(0);
16618                                    }
16619    
16620                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S,
16621                                            finderArgs, count);
16622    
16623                                    closeSession(session);
16624                            }
16625                    }
16626    
16627                    return count.intValue();
16628            }
16629    
16630            /**
16631             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
16632             *
16633             * @param groupId the group ID
16634             * @param categoryId the category ID
16635             * @param status the status
16636             * @return the number of matching message-boards messages that the user has permission to view
16637             * @throws SystemException if a system exception occurred
16638             */
16639            public int filterCountByG_C_S(long groupId, long categoryId, int status)
16640                    throws SystemException {
16641                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16642                            return countByG_C_S(groupId, categoryId, status);
16643                    }
16644    
16645                    StringBundler query = new StringBundler(4);
16646    
16647                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16648    
16649                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
16650    
16651                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
16652    
16653                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
16654    
16655                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16656                                    MBMessage.class.getName(),
16657                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16658    
16659                    Session session = null;
16660    
16661                    try {
16662                            session = openSession();
16663    
16664                            SQLQuery q = session.createSQLQuery(sql);
16665    
16666                            q.addScalar(COUNT_COLUMN_NAME,
16667                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16668    
16669                            QueryPos qPos = QueryPos.getInstance(q);
16670    
16671                            qPos.add(groupId);
16672    
16673                            qPos.add(categoryId);
16674    
16675                            qPos.add(status);
16676    
16677                            Long count = (Long)q.uniqueResult();
16678    
16679                            return count.intValue();
16680                    }
16681                    catch (Exception e) {
16682                            throw processException(e);
16683                    }
16684                    finally {
16685                            closeSession(session);
16686                    }
16687            }
16688    
16689            /**
16690             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
16691             *
16692             * @param userId the user ID
16693             * @param classNameId the class name ID
16694             * @param classPK the class p k
16695             * @return the number of matching message-boards messages
16696             * @throws SystemException if a system exception occurred
16697             */
16698            public int countByU_C_C(long userId, long classNameId, long classPK)
16699                    throws SystemException {
16700                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
16701    
16702                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C,
16703                                    finderArgs, this);
16704    
16705                    if (count == null) {
16706                            StringBundler query = new StringBundler(4);
16707    
16708                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16709    
16710                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
16711    
16712                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
16713    
16714                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
16715    
16716                            String sql = query.toString();
16717    
16718                            Session session = null;
16719    
16720                            try {
16721                                    session = openSession();
16722    
16723                                    Query q = session.createQuery(sql);
16724    
16725                                    QueryPos qPos = QueryPos.getInstance(q);
16726    
16727                                    qPos.add(userId);
16728    
16729                                    qPos.add(classNameId);
16730    
16731                                    qPos.add(classPK);
16732    
16733                                    count = (Long)q.uniqueResult();
16734                            }
16735                            catch (Exception e) {
16736                                    throw processException(e);
16737                            }
16738                            finally {
16739                                    if (count == null) {
16740                                            count = Long.valueOf(0);
16741                                    }
16742    
16743                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C,
16744                                            finderArgs, count);
16745    
16746                                    closeSession(session);
16747                            }
16748                    }
16749    
16750                    return count.intValue();
16751            }
16752    
16753            /**
16754             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
16755             *
16756             * @param userId the user ID
16757             * @param classNameId the class name ID
16758             * @param status the status
16759             * @return the number of matching message-boards messages
16760             * @throws SystemException if a system exception occurred
16761             */
16762            public int countByU_C_S(long userId, long classNameId, int status)
16763                    throws SystemException {
16764                    Object[] finderArgs = new Object[] { userId, classNameId, status };
16765    
16766                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_S,
16767                                    finderArgs, this);
16768    
16769                    if (count == null) {
16770                            StringBundler query = new StringBundler(4);
16771    
16772                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16773    
16774                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
16775    
16776                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
16777    
16778                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
16779    
16780                            String sql = query.toString();
16781    
16782                            Session session = null;
16783    
16784                            try {
16785                                    session = openSession();
16786    
16787                                    Query q = session.createQuery(sql);
16788    
16789                                    QueryPos qPos = QueryPos.getInstance(q);
16790    
16791                                    qPos.add(userId);
16792    
16793                                    qPos.add(classNameId);
16794    
16795                                    qPos.add(status);
16796    
16797                                    count = (Long)q.uniqueResult();
16798                            }
16799                            catch (Exception e) {
16800                                    throw processException(e);
16801                            }
16802                            finally {
16803                                    if (count == null) {
16804                                            count = Long.valueOf(0);
16805                                    }
16806    
16807                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_S,
16808                                            finderArgs, count);
16809    
16810                                    closeSession(session);
16811                            }
16812                    }
16813    
16814                    return count.intValue();
16815            }
16816    
16817            /**
16818             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
16819             *
16820             * @param userId the user ID
16821             * @param classNameIds the class name IDs
16822             * @param status the status
16823             * @return the number of matching message-boards messages
16824             * @throws SystemException if a system exception occurred
16825             */
16826            public int countByU_C_S(long userId, long[] classNameIds, int status)
16827                    throws SystemException {
16828                    Object[] finderArgs = new Object[] {
16829                                    userId, StringUtil.merge(classNameIds), status
16830                            };
16831    
16832                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_S,
16833                                    finderArgs, this);
16834    
16835                    if (count == null) {
16836                            StringBundler query = new StringBundler();
16837    
16838                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16839    
16840                            boolean conjunctionable = false;
16841    
16842                            if (conjunctionable) {
16843                                    query.append(WHERE_AND);
16844                            }
16845    
16846                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
16847    
16848                            conjunctionable = true;
16849    
16850                            if ((classNameIds == null) || (classNameIds.length > 0)) {
16851                                    if (conjunctionable) {
16852                                            query.append(WHERE_AND);
16853                                    }
16854    
16855                                    query.append(StringPool.OPEN_PARENTHESIS);
16856    
16857                                    for (int i = 0; i < classNameIds.length; i++) {
16858                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
16859    
16860                                            if ((i + 1) < classNameIds.length) {
16861                                                    query.append(WHERE_OR);
16862                                            }
16863                                    }
16864    
16865                                    query.append(StringPool.CLOSE_PARENTHESIS);
16866    
16867                                    conjunctionable = true;
16868                            }
16869    
16870                            if (conjunctionable) {
16871                                    query.append(WHERE_AND);
16872                            }
16873    
16874                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
16875    
16876                            conjunctionable = true;
16877    
16878                            String sql = query.toString();
16879    
16880                            Session session = null;
16881    
16882                            try {
16883                                    session = openSession();
16884    
16885                                    Query q = session.createQuery(sql);
16886    
16887                                    QueryPos qPos = QueryPos.getInstance(q);
16888    
16889                                    qPos.add(userId);
16890    
16891                                    if (classNameIds != null) {
16892                                            qPos.add(classNameIds);
16893                                    }
16894    
16895                                    qPos.add(status);
16896    
16897                                    count = (Long)q.uniqueResult();
16898                            }
16899                            catch (Exception e) {
16900                                    throw processException(e);
16901                            }
16902                            finally {
16903                                    if (count == null) {
16904                                            count = Long.valueOf(0);
16905                                    }
16906    
16907                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_S,
16908                                            finderArgs, count);
16909    
16910                                    closeSession(session);
16911                            }
16912                    }
16913    
16914                    return count.intValue();
16915            }
16916    
16917            /**
16918             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
16919             *
16920             * @param classNameId the class name ID
16921             * @param classPK the class p k
16922             * @param status the status
16923             * @return the number of matching message-boards messages
16924             * @throws SystemException if a system exception occurred
16925             */
16926            public int countByC_C_S(long classNameId, long classPK, int status)
16927                    throws SystemException {
16928                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
16929    
16930                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_S,
16931                                    finderArgs, this);
16932    
16933                    if (count == null) {
16934                            StringBundler query = new StringBundler(4);
16935    
16936                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16937    
16938                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
16939    
16940                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
16941    
16942                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
16943    
16944                            String sql = query.toString();
16945    
16946                            Session session = null;
16947    
16948                            try {
16949                                    session = openSession();
16950    
16951                                    Query q = session.createQuery(sql);
16952    
16953                                    QueryPos qPos = QueryPos.getInstance(q);
16954    
16955                                    qPos.add(classNameId);
16956    
16957                                    qPos.add(classPK);
16958    
16959                                    qPos.add(status);
16960    
16961                                    count = (Long)q.uniqueResult();
16962                            }
16963                            catch (Exception e) {
16964                                    throw processException(e);
16965                            }
16966                            finally {
16967                                    if (count == null) {
16968                                            count = Long.valueOf(0);
16969                                    }
16970    
16971                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_S,
16972                                            finderArgs, count);
16973    
16974                                    closeSession(session);
16975                            }
16976                    }
16977    
16978                    return count.intValue();
16979            }
16980    
16981            /**
16982             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16983             *
16984             * @param groupId the group ID
16985             * @param categoryId the category ID
16986             * @param threadId the thread ID
16987             * @param answer the answer
16988             * @return the number of matching message-boards messages
16989             * @throws SystemException if a system exception occurred
16990             */
16991            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
16992                    boolean answer) throws SystemException {
16993                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
16994    
16995                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T_A,
16996                                    finderArgs, this);
16997    
16998                    if (count == null) {
16999                            StringBundler query = new StringBundler(5);
17000    
17001                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17002    
17003                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17004    
17005                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17006    
17007                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17008    
17009                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17010    
17011                            String sql = query.toString();
17012    
17013                            Session session = null;
17014    
17015                            try {
17016                                    session = openSession();
17017    
17018                                    Query q = session.createQuery(sql);
17019    
17020                                    QueryPos qPos = QueryPos.getInstance(q);
17021    
17022                                    qPos.add(groupId);
17023    
17024                                    qPos.add(categoryId);
17025    
17026                                    qPos.add(threadId);
17027    
17028                                    qPos.add(answer);
17029    
17030                                    count = (Long)q.uniqueResult();
17031                            }
17032                            catch (Exception e) {
17033                                    throw processException(e);
17034                            }
17035                            finally {
17036                                    if (count == null) {
17037                                            count = Long.valueOf(0);
17038                                    }
17039    
17040                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T_A,
17041                                            finderArgs, count);
17042    
17043                                    closeSession(session);
17044                            }
17045                    }
17046    
17047                    return count.intValue();
17048            }
17049    
17050            /**
17051             * 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;.
17052             *
17053             * @param groupId the group ID
17054             * @param categoryId the category ID
17055             * @param threadId the thread ID
17056             * @param answer the answer
17057             * @return the number of matching message-boards messages that the user has permission to view
17058             * @throws SystemException if a system exception occurred
17059             */
17060            public int filterCountByG_C_T_A(long groupId, long categoryId,
17061                    long threadId, boolean answer) throws SystemException {
17062                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17063                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
17064                    }
17065    
17066                    StringBundler query = new StringBundler(5);
17067    
17068                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17069    
17070                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17071    
17072                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17073    
17074                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17075    
17076                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17077    
17078                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17079                                    MBMessage.class.getName(),
17080                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17081    
17082                    Session session = null;
17083    
17084                    try {
17085                            session = openSession();
17086    
17087                            SQLQuery q = session.createSQLQuery(sql);
17088    
17089                            q.addScalar(COUNT_COLUMN_NAME,
17090                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17091    
17092                            QueryPos qPos = QueryPos.getInstance(q);
17093    
17094                            qPos.add(groupId);
17095    
17096                            qPos.add(categoryId);
17097    
17098                            qPos.add(threadId);
17099    
17100                            qPos.add(answer);
17101    
17102                            Long count = (Long)q.uniqueResult();
17103    
17104                            return count.intValue();
17105                    }
17106                    catch (Exception e) {
17107                            throw processException(e);
17108                    }
17109                    finally {
17110                            closeSession(session);
17111                    }
17112            }
17113    
17114            /**
17115             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17116             *
17117             * @param groupId the group ID
17118             * @param categoryId the category ID
17119             * @param threadId the thread ID
17120             * @param status the status
17121             * @return the number of matching message-boards messages
17122             * @throws SystemException if a system exception occurred
17123             */
17124            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
17125                    int status) throws SystemException {
17126                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
17127    
17128                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T_S,
17129                                    finderArgs, this);
17130    
17131                    if (count == null) {
17132                            StringBundler query = new StringBundler(5);
17133    
17134                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17135    
17136                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17137    
17138                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17139    
17140                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17141    
17142                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17143    
17144                            String sql = query.toString();
17145    
17146                            Session session = null;
17147    
17148                            try {
17149                                    session = openSession();
17150    
17151                                    Query q = session.createQuery(sql);
17152    
17153                                    QueryPos qPos = QueryPos.getInstance(q);
17154    
17155                                    qPos.add(groupId);
17156    
17157                                    qPos.add(categoryId);
17158    
17159                                    qPos.add(threadId);
17160    
17161                                    qPos.add(status);
17162    
17163                                    count = (Long)q.uniqueResult();
17164                            }
17165                            catch (Exception e) {
17166                                    throw processException(e);
17167                            }
17168                            finally {
17169                                    if (count == null) {
17170                                            count = Long.valueOf(0);
17171                                    }
17172    
17173                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T_S,
17174                                            finderArgs, count);
17175    
17176                                    closeSession(session);
17177                            }
17178                    }
17179    
17180                    return count.intValue();
17181            }
17182    
17183            /**
17184             * 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;.
17185             *
17186             * @param groupId the group ID
17187             * @param categoryId the category ID
17188             * @param threadId the thread ID
17189             * @param status the status
17190             * @return the number of matching message-boards messages that the user has permission to view
17191             * @throws SystemException if a system exception occurred
17192             */
17193            public int filterCountByG_C_T_S(long groupId, long categoryId,
17194                    long threadId, int status) throws SystemException {
17195                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17196                            return countByG_C_T_S(groupId, categoryId, threadId, status);
17197                    }
17198    
17199                    StringBundler query = new StringBundler(5);
17200    
17201                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17202    
17203                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17204    
17205                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17206    
17207                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17208    
17209                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17210    
17211                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17212                                    MBMessage.class.getName(),
17213                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17214    
17215                    Session session = null;
17216    
17217                    try {
17218                            session = openSession();
17219    
17220                            SQLQuery q = session.createSQLQuery(sql);
17221    
17222                            q.addScalar(COUNT_COLUMN_NAME,
17223                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17224    
17225                            QueryPos qPos = QueryPos.getInstance(q);
17226    
17227                            qPos.add(groupId);
17228    
17229                            qPos.add(categoryId);
17230    
17231                            qPos.add(threadId);
17232    
17233                            qPos.add(status);
17234    
17235                            Long count = (Long)q.uniqueResult();
17236    
17237                            return count.intValue();
17238                    }
17239                    catch (Exception e) {
17240                            throw processException(e);
17241                    }
17242                    finally {
17243                            closeSession(session);
17244                    }
17245            }
17246    
17247            /**
17248             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17249             *
17250             * @param userId the user ID
17251             * @param classNameId the class name ID
17252             * @param classPK the class p k
17253             * @param status the status
17254             * @return the number of matching message-boards messages
17255             * @throws SystemException if a system exception occurred
17256             */
17257            public int countByU_C_C_S(long userId, long classNameId, long classPK,
17258                    int status) throws SystemException {
17259                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
17260    
17261                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C_S,
17262                                    finderArgs, this);
17263    
17264                    if (count == null) {
17265                            StringBundler query = new StringBundler(5);
17266    
17267                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17268    
17269                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
17270    
17271                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
17272    
17273                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
17274    
17275                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
17276    
17277                            String sql = query.toString();
17278    
17279                            Session session = null;
17280    
17281                            try {
17282                                    session = openSession();
17283    
17284                                    Query q = session.createQuery(sql);
17285    
17286                                    QueryPos qPos = QueryPos.getInstance(q);
17287    
17288                                    qPos.add(userId);
17289    
17290                                    qPos.add(classNameId);
17291    
17292                                    qPos.add(classPK);
17293    
17294                                    qPos.add(status);
17295    
17296                                    count = (Long)q.uniqueResult();
17297                            }
17298                            catch (Exception e) {
17299                                    throw processException(e);
17300                            }
17301                            finally {
17302                                    if (count == null) {
17303                                            count = Long.valueOf(0);
17304                                    }
17305    
17306                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C_S,
17307                                            finderArgs, count);
17308    
17309                                    closeSession(session);
17310                            }
17311                    }
17312    
17313                    return count.intValue();
17314            }
17315    
17316            /**
17317             * Returns the number of message-boards messages.
17318             *
17319             * @return the number of message-boards messages
17320             * @throws SystemException if a system exception occurred
17321             */
17322            public int countAll() throws SystemException {
17323                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
17324                                    FINDER_ARGS_EMPTY, this);
17325    
17326                    if (count == null) {
17327                            Session session = null;
17328    
17329                            try {
17330                                    session = openSession();
17331    
17332                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
17333    
17334                                    count = (Long)q.uniqueResult();
17335                            }
17336                            catch (Exception e) {
17337                                    throw processException(e);
17338                            }
17339                            finally {
17340                                    if (count == null) {
17341                                            count = Long.valueOf(0);
17342                                    }
17343    
17344                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
17345                                            FINDER_ARGS_EMPTY, count);
17346    
17347                                    closeSession(session);
17348                            }
17349                    }
17350    
17351                    return count.intValue();
17352            }
17353    
17354            /**
17355             * Initializes the message-boards message persistence.
17356             */
17357            public void afterPropertiesSet() {
17358                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
17359                                            com.liferay.portal.util.PropsUtil.get(
17360                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBMessage")));
17361    
17362                    if (listenerClassNames.length > 0) {
17363                            try {
17364                                    List<ModelListener<MBMessage>> listenersList = new ArrayList<ModelListener<MBMessage>>();
17365    
17366                                    for (String listenerClassName : listenerClassNames) {
17367                                            listenersList.add((ModelListener<MBMessage>)InstanceFactory.newInstance(
17368                                                            listenerClassName));
17369                                    }
17370    
17371                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
17372                            }
17373                            catch (Exception e) {
17374                                    _log.error(e);
17375                            }
17376                    }
17377            }
17378    
17379            public void destroy() {
17380                    EntityCacheUtil.removeCache(MBMessageImpl.class.getName());
17381                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
17382                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
17383            }
17384    
17385            @BeanReference(type = MBBanPersistence.class)
17386            protected MBBanPersistence mbBanPersistence;
17387            @BeanReference(type = MBCategoryPersistence.class)
17388            protected MBCategoryPersistence mbCategoryPersistence;
17389            @BeanReference(type = MBDiscussionPersistence.class)
17390            protected MBDiscussionPersistence mbDiscussionPersistence;
17391            @BeanReference(type = MBMailingListPersistence.class)
17392            protected MBMailingListPersistence mbMailingListPersistence;
17393            @BeanReference(type = MBMessagePersistence.class)
17394            protected MBMessagePersistence mbMessagePersistence;
17395            @BeanReference(type = MBStatsUserPersistence.class)
17396            protected MBStatsUserPersistence mbStatsUserPersistence;
17397            @BeanReference(type = MBThreadPersistence.class)
17398            protected MBThreadPersistence mbThreadPersistence;
17399            @BeanReference(type = MBThreadFlagPersistence.class)
17400            protected MBThreadFlagPersistence mbThreadFlagPersistence;
17401            @BeanReference(type = CompanyPersistence.class)
17402            protected CompanyPersistence companyPersistence;
17403            @BeanReference(type = GroupPersistence.class)
17404            protected GroupPersistence groupPersistence;
17405            @BeanReference(type = LockPersistence.class)
17406            protected LockPersistence lockPersistence;
17407            @BeanReference(type = PortletPreferencesPersistence.class)
17408            protected PortletPreferencesPersistence portletPreferencesPersistence;
17409            @BeanReference(type = ResourcePersistence.class)
17410            protected ResourcePersistence resourcePersistence;
17411            @BeanReference(type = SubscriptionPersistence.class)
17412            protected SubscriptionPersistence subscriptionPersistence;
17413            @BeanReference(type = UserPersistence.class)
17414            protected UserPersistence userPersistence;
17415            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
17416            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
17417            @BeanReference(type = AssetEntryPersistence.class)
17418            protected AssetEntryPersistence assetEntryPersistence;
17419            @BeanReference(type = AssetLinkPersistence.class)
17420            protected AssetLinkPersistence assetLinkPersistence;
17421            @BeanReference(type = AssetTagPersistence.class)
17422            protected AssetTagPersistence assetTagPersistence;
17423            @BeanReference(type = BlogsEntryPersistence.class)
17424            protected BlogsEntryPersistence blogsEntryPersistence;
17425            @BeanReference(type = ExpandoValuePersistence.class)
17426            protected ExpandoValuePersistence expandoValuePersistence;
17427            @BeanReference(type = RatingsStatsPersistence.class)
17428            protected RatingsStatsPersistence ratingsStatsPersistence;
17429            @BeanReference(type = SocialActivityPersistence.class)
17430            protected SocialActivityPersistence socialActivityPersistence;
17431            @BeanReference(type = WikiPagePersistence.class)
17432            protected WikiPagePersistence wikiPagePersistence;
17433            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
17434            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
17435            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
17436            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
17437            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
17438            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
17439            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?)";
17440            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
17441            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
17442            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?) AND ";
17443            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
17444            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ?";
17445            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ?";
17446            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
17447            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
17448            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ?";
17449            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
17450            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
17451            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
17452            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
17453            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
17454            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
17455            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
17456            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ?";
17457            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
17458            private static final String _FINDER_COLUMN_U_C_USERID_5 = "(" +
17459                    _removeConjunction(_FINDER_COLUMN_U_C_USERID_2) + ")";
17460            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
17461            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_5 = "(" +
17462                    _removeConjunction(_FINDER_COLUMN_U_C_CLASSNAMEID_2) + ")";
17463            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
17464            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
17465            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
17466            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
17467            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
17468            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
17469            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
17470            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
17471            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
17472            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
17473            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
17474            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
17475            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ?";
17476            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
17477            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17478            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
17479            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
17480            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17481            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
17482            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
17483            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
17484            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
17485            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
17486            private static final String _FINDER_COLUMN_U_C_S_USERID_5 = "(" +
17487                    _removeConjunction(_FINDER_COLUMN_U_C_S_USERID_2) + ")";
17488            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
17489            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_5 = "(" +
17490                    _removeConjunction(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2) + ")";
17491            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
17492            private static final String _FINDER_COLUMN_U_C_S_STATUS_5 = "(" +
17493                    _removeConjunction(_FINDER_COLUMN_U_C_S_STATUS_2) + ")";
17494            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
17495            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
17496            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
17497            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
17498            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17499            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
17500            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
17501            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
17502            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17503            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
17504            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
17505            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
17506            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
17507            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
17508            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
17509    
17510            private static String _removeConjunction(String sql) {
17511                    int pos = sql.indexOf(" AND ");
17512    
17513                    if (pos != -1) {
17514                            sql = sql.substring(0, pos);
17515                    }
17516    
17517                    return sql;
17518            }
17519    
17520            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
17521            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
17522            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
17523                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
17524            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
17525                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
17526            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
17527            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
17528            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
17529            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
17530            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
17531            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
17532            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
17533            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
17534            private static Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
17535            private static MBMessage _nullMBMessage = new MBMessageImpl() {
17536                            @Override
17537                            public Object clone() {
17538                                    return this;
17539                            }
17540    
17541                            @Override
17542                            public CacheModel<MBMessage> toCacheModel() {
17543                                    return _nullMBMessageCacheModel;
17544                            }
17545                    };
17546    
17547            private static CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
17548                            public MBMessage toEntityModel() {
17549                                    return _nullMBMessage;
17550                            }
17551                    };
17552    }