001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.sanitizer.Sanitizer;
032    import com.liferay.portal.kernel.sanitizer.SanitizerException;
033    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
034    import com.liferay.portal.kernel.util.ArrayUtil;
035    import com.liferay.portal.kernel.util.ContentTypes;
036    import com.liferay.portal.kernel.util.GetterUtil;
037    import com.liferay.portal.kernel.util.InstanceFactory;
038    import com.liferay.portal.kernel.util.OrderByComparator;
039    import com.liferay.portal.kernel.util.StringBundler;
040    import com.liferay.portal.kernel.util.StringPool;
041    import com.liferay.portal.kernel.util.StringUtil;
042    import com.liferay.portal.kernel.util.Validator;
043    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
044    import com.liferay.portal.model.CacheModel;
045    import com.liferay.portal.model.ModelListener;
046    import com.liferay.portal.security.auth.PrincipalThreadLocal;
047    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
048    import com.liferay.portal.service.persistence.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.SubscriptionPersistence;
053    import com.liferay.portal.service.persistence.UserPersistence;
054    import com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence;
055    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
056    
057    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
058    import com.liferay.portlet.asset.service.persistence.AssetLinkPersistence;
059    import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
060    import com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence;
061    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
062    import com.liferay.portlet.messageboards.NoSuchMessageException;
063    import com.liferay.portlet.messageboards.model.MBMessage;
064    import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
065    import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
066    import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
067    import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
068    import com.liferay.portlet.wiki.service.persistence.WikiPagePersistence;
069    
070    import java.io.Serializable;
071    
072    import java.util.ArrayList;
073    import java.util.Collections;
074    import java.util.List;
075    
076    /**
077     * The persistence implementation for the message-boards message service.
078     *
079     * <p>
080     * Caching information and settings can be found in <code>portal.properties</code>
081     * </p>
082     *
083     * @author Brian Wing Shun Chan
084     * @see MBMessagePersistence
085     * @see MBMessageUtil
086     * @generated
087     */
088    public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
089            implements MBMessagePersistence {
090            /*
091             * NOTE FOR DEVELOPERS:
092             *
093             * 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.
094             */
095            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
096            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
097                    ".List1";
098            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
099                    ".List2";
100            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
101                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
102                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
103                            new String[] {
104                                    String.class.getName(),
105                                    
106                            "java.lang.Integer", "java.lang.Integer",
107                                    "com.liferay.portal.kernel.util.OrderByComparator"
108                            });
109            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
110                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
111                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
112                            new String[] { String.class.getName() },
113                            MBMessageModelImpl.UUID_COLUMN_BITMASK);
114            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
115                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
116                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
117                            new String[] { String.class.getName() });
118            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
119                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
120                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
121                            new String[] { String.class.getName(), Long.class.getName() },
122                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
123                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
124            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
125                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
126                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
127                            new String[] { String.class.getName(), Long.class.getName() });
128            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
129                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
130                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
131                            new String[] {
132                                    String.class.getName(), Long.class.getName(),
133                                    
134                            "java.lang.Integer", "java.lang.Integer",
135                                    "com.liferay.portal.kernel.util.OrderByComparator"
136                            });
137            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
138                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
139                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
140                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
141                            new String[] { String.class.getName(), Long.class.getName() },
142                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
143                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK);
144            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
145                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
146                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
147                            new String[] { String.class.getName(), Long.class.getName() });
148            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
149                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
150                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
151                            new String[] {
152                                    Long.class.getName(),
153                                    
154                            "java.lang.Integer", "java.lang.Integer",
155                                    "com.liferay.portal.kernel.util.OrderByComparator"
156                            });
157            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
158                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
159                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
160                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
161                            new String[] { Long.class.getName() },
162                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
163            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
164                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
165                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
166                            new String[] { Long.class.getName() });
167            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
168                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
169                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
170                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
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_COMPANYID =
178                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
179                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
180                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
181                            new String[] { Long.class.getName() },
182                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK);
183            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
184                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
185                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
186                            new String[] { Long.class.getName() });
187            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
188                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
189                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
190                            new String[] {
191                                    Long.class.getName(),
192                                    
193                            "java.lang.Integer", "java.lang.Integer",
194                                    "com.liferay.portal.kernel.util.OrderByComparator"
195                            });
196            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
197                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
198                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
199                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
200                            new String[] { Long.class.getName() },
201                            MBMessageModelImpl.THREADID_COLUMN_BITMASK);
202            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
203                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
204                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
205                            new String[] { Long.class.getName() });
206            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
207                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
208                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
209                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
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_THREADREPLIES =
217                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
218                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
219                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
220                            new String[] { Long.class.getName() },
221                            MBMessageModelImpl.THREADID_COLUMN_BITMASK);
222            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
223                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
224                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
225                            new String[] { Long.class.getName() });
226            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
227                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
228                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
229                            new String[] {
230                                    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_USERID =
236                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
237                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
238                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
239                            new String[] { Long.class.getName() },
240                            MBMessageModelImpl.USERID_COLUMN_BITMASK);
241            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
242                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
243                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
244                            new String[] { Long.class.getName() });
245            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
246                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
247                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
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_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
255                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
256                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
257                            new String[] { Long.class.getName(), Long.class.getName() },
258                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
259                            MBMessageModelImpl.USERID_COLUMN_BITMASK);
260            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
261                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
262                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
263                            new String[] { Long.class.getName(), Long.class.getName() });
264            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
265                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
266                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
267                            new String[] {
268                                    Long.class.getName(), Long.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_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
274                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
275                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
276                            new String[] { Long.class.getName(), Long.class.getName() },
277                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
278                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK);
279            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
280                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
281                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
282                            new String[] { Long.class.getName(), Long.class.getName() });
283            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
284                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
285                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_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_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
293                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
294                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
295                            new String[] { Long.class.getName(), Integer.class.getName() },
296                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
297                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
298            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
299                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
300                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
301                            new String[] { Long.class.getName(), Integer.class.getName() });
302            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
303                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
304                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
305                            new String[] {
306                                    Long.class.getName(), Integer.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_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
312                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
313                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
314                            new String[] { Long.class.getName(), Integer.class.getName() },
315                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
316                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
317            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
318                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
319                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
320                            new String[] { Long.class.getName(), Integer.class.getName() });
321            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
322                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
323                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_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_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
331                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
332                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
333                            new String[] { Long.class.getName(), Long.class.getName() },
334                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
335                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK);
336            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
337                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
338                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
339                            new String[] { Long.class.getName(), Long.class.getName() });
340            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
341                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
342                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C",
343                            new String[] { Long.class.getName(), Long.class.getName() });
344            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
345                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
346                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
347                            new String[] {
348                                    Long.class.getName(), Long.class.getName(),
349                                    
350                            "java.lang.Integer", "java.lang.Integer",
351                                    "com.liferay.portal.kernel.util.OrderByComparator"
352                            });
353            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
354                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
355                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
356                            new String[] { Long.class.getName(), Long.class.getName() },
357                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
358                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK);
359            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
360                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
361                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
362                            new String[] { Long.class.getName(), Long.class.getName() });
363            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
364                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
365                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
366                            new String[] {
367                                    Long.class.getName(), Long.class.getName(),
368                                    
369                            "java.lang.Integer", "java.lang.Integer",
370                                    "com.liferay.portal.kernel.util.OrderByComparator"
371                            });
372            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
373                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
374                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
375                            new String[] { Long.class.getName(), Long.class.getName() },
376                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
377                            MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK);
378            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
379                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
380                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
381                            new String[] { Long.class.getName(), Long.class.getName() });
382            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
383                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
384                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
385                            new String[] {
386                                    Long.class.getName(), Boolean.class.getName(),
387                                    
388                            "java.lang.Integer", "java.lang.Integer",
389                                    "com.liferay.portal.kernel.util.OrderByComparator"
390                            });
391            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
392                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
393                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
394                            new String[] { Long.class.getName(), Boolean.class.getName() },
395                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
396                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK);
397            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
398                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
399                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
400                            new String[] { Long.class.getName(), Boolean.class.getName() });
401            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
402                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
403                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
404                            new String[] {
405                                    Long.class.getName(), Integer.class.getName(),
406                                    
407                            "java.lang.Integer", "java.lang.Integer",
408                                    "com.liferay.portal.kernel.util.OrderByComparator"
409                            });
410            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
411                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
412                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
413                            new String[] { Long.class.getName(), Integer.class.getName() },
414                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
415                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
416            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
417                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
418                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
419                            new String[] { Long.class.getName(), Integer.class.getName() });
420            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
421                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
422                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
423                            new String[] {
424                                    Long.class.getName(), Integer.class.getName(),
425                                    
426                            "java.lang.Integer", "java.lang.Integer",
427                                    "com.liferay.portal.kernel.util.OrderByComparator"
428                            });
429            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
430                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
431                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
432                            new String[] { Long.class.getName(), Integer.class.getName() },
433                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
434                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
435            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
436                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
437                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
438                            new String[] { Long.class.getName(), Integer.class.getName() });
439            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
440                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
441                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
442                            new String[] {
443                                    Long.class.getName(), Long.class.getName(),
444                                    Integer.class.getName(),
445                                    
446                            "java.lang.Integer", "java.lang.Integer",
447                                    "com.liferay.portal.kernel.util.OrderByComparator"
448                            });
449            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
450                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
451                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
452                            new String[] {
453                                    Long.class.getName(), Long.class.getName(),
454                                    Integer.class.getName()
455                            },
456                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
457                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
458                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
459            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
460                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
461                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
462                            new String[] {
463                                    Long.class.getName(), Long.class.getName(),
464                                    Integer.class.getName()
465                            });
466            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
467                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
468                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
469                            new String[] {
470                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
471                                    
472                            "java.lang.Integer", "java.lang.Integer",
473                                    "com.liferay.portal.kernel.util.OrderByComparator"
474                            });
475            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
476                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
477                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
478                            new String[] {
479                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
480                            },
481                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
482                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
483                            MBMessageModelImpl.THREADID_COLUMN_BITMASK);
484            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
485                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
486                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
487                            new String[] {
488                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
489                            });
490            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
491                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
492                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
493                            new String[] {
494                                    Long.class.getName(), Long.class.getName(),
495                                    Integer.class.getName(),
496                                    
497                            "java.lang.Integer", "java.lang.Integer",
498                                    "com.liferay.portal.kernel.util.OrderByComparator"
499                            });
500            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
501                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
502                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
503                            new String[] {
504                                    Long.class.getName(), Long.class.getName(),
505                                    Integer.class.getName()
506                            },
507                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
508                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
509                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
510            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
511                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
512                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
513                            new String[] {
514                                    Long.class.getName(), Long.class.getName(),
515                                    Integer.class.getName()
516                            });
517            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
518                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
519                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
520                            new String[] {
521                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
522                                    
523                            "java.lang.Integer", "java.lang.Integer",
524                                    "com.liferay.portal.kernel.util.OrderByComparator"
525                            });
526            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
527                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
528                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
529                            new String[] {
530                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
531                            },
532                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
533                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
534                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK);
535            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
536                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
537                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
538                            new String[] {
539                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
540                            });
541            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
542                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
543                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
544                            new String[] {
545                                    Long.class.getName(), Long.class.getName(),
546                                    Integer.class.getName(),
547                                    
548                            "java.lang.Integer", "java.lang.Integer",
549                                    "com.liferay.portal.kernel.util.OrderByComparator"
550                            });
551            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
552                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
553                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
554                            new String[] {
555                                    Long.class.getName(), Long.class.getName(),
556                                    Integer.class.getName()
557                            },
558                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
559                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
560                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
561            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
562                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
563                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
564                            new String[] {
565                                    Long.class.getName(), Long.class.getName(),
566                                    Integer.class.getName()
567                            });
568            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
569                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
570                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C_S",
571                            new String[] {
572                                    Long.class.getName(), Long.class.getName(),
573                                    Integer.class.getName()
574                            });
575            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
576                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
577                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
578                            new String[] {
579                                    Long.class.getName(), Long.class.getName(),
580                                    Integer.class.getName(),
581                                    
582                            "java.lang.Integer", "java.lang.Integer",
583                                    "com.liferay.portal.kernel.util.OrderByComparator"
584                            });
585            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
586                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
587                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
588                            new String[] {
589                                    Long.class.getName(), Long.class.getName(),
590                                    Integer.class.getName()
591                            },
592                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
593                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
594                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
595            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
596                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
597                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
598                            new String[] {
599                                    Long.class.getName(), Long.class.getName(),
600                                    Integer.class.getName()
601                            });
602            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
603                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
604                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
605                            new String[] {
606                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
607                                    Boolean.class.getName(),
608                                    
609                            "java.lang.Integer", "java.lang.Integer",
610                                    "com.liferay.portal.kernel.util.OrderByComparator"
611                            });
612            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
613                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
614                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
615                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
616                            new String[] {
617                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
618                                    Boolean.class.getName()
619                            },
620                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
621                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
622                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
623                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK);
624            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
625                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
626                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
627                            new String[] {
628                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
629                                    Boolean.class.getName()
630                            });
631            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
632                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
633                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
634                            new String[] {
635                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
636                                    Integer.class.getName(),
637                                    
638                            "java.lang.Integer", "java.lang.Integer",
639                                    "com.liferay.portal.kernel.util.OrderByComparator"
640                            });
641            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
642                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
643                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
644                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
645                            new String[] {
646                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
647                                    Integer.class.getName()
648                            },
649                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
650                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
651                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
652                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
653            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
654                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
655                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
656                            new String[] {
657                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
658                                    Integer.class.getName()
659                            });
660            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
661                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
662                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
663                            new String[] {
664                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
665                                    Integer.class.getName(),
666                                    
667                            "java.lang.Integer", "java.lang.Integer",
668                                    "com.liferay.portal.kernel.util.OrderByComparator"
669                            });
670            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
671                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
672                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
673                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
674                            new String[] {
675                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
676                                    Integer.class.getName()
677                            },
678                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
679                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
680                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
681                            MBMessageModelImpl.STATUS_COLUMN_BITMASK);
682            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
683                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
684                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
685                            new String[] {
686                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
687                                    Integer.class.getName()
688                            });
689            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
690                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
691                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
692            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
693                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
694                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
695            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
696                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
697                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
698    
699            /**
700             * Caches the message-boards message in the entity cache if it is enabled.
701             *
702             * @param mbMessage the message-boards message
703             */
704            public void cacheResult(MBMessage mbMessage) {
705                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
706                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
707    
708                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
709                            new Object[] {
710                                    mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
711                            }, mbMessage);
712    
713                    mbMessage.resetOriginalValues();
714            }
715    
716            /**
717             * Caches the message-boards messages in the entity cache if it is enabled.
718             *
719             * @param mbMessages the message-boards messages
720             */
721            public void cacheResult(List<MBMessage> mbMessages) {
722                    for (MBMessage mbMessage : mbMessages) {
723                            if (EntityCacheUtil.getResult(
724                                                    MBMessageModelImpl.ENTITY_CACHE_ENABLED,
725                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
726                                    cacheResult(mbMessage);
727                            }
728                            else {
729                                    mbMessage.resetOriginalValues();
730                            }
731                    }
732            }
733    
734            /**
735             * Clears the cache for all message-boards messages.
736             *
737             * <p>
738             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
739             * </p>
740             */
741            @Override
742            public void clearCache() {
743                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
744                            CacheRegistryUtil.clear(MBMessageImpl.class.getName());
745                    }
746    
747                    EntityCacheUtil.clearCache(MBMessageImpl.class.getName());
748    
749                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
750                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
751                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
752            }
753    
754            /**
755             * Clears the cache for the message-boards message.
756             *
757             * <p>
758             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
759             * </p>
760             */
761            @Override
762            public void clearCache(MBMessage mbMessage) {
763                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
764                            MBMessageImpl.class, mbMessage.getPrimaryKey());
765    
766                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
767                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
768    
769                    clearUniqueFindersCache(mbMessage);
770            }
771    
772            @Override
773            public void clearCache(List<MBMessage> mbMessages) {
774                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
775                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
776    
777                    for (MBMessage mbMessage : mbMessages) {
778                            EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
779                                    MBMessageImpl.class, mbMessage.getPrimaryKey());
780    
781                            clearUniqueFindersCache(mbMessage);
782                    }
783            }
784    
785            protected void clearUniqueFindersCache(MBMessage mbMessage) {
786                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
787                            new Object[] {
788                                    mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
789                            });
790            }
791    
792            /**
793             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
794             *
795             * @param messageId the primary key for the new message-boards message
796             * @return the new message-boards message
797             */
798            public MBMessage create(long messageId) {
799                    MBMessage mbMessage = new MBMessageImpl();
800    
801                    mbMessage.setNew(true);
802                    mbMessage.setPrimaryKey(messageId);
803    
804                    String uuid = PortalUUIDUtil.generate();
805    
806                    mbMessage.setUuid(uuid);
807    
808                    return mbMessage;
809            }
810    
811            /**
812             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
813             *
814             * @param messageId the primary key of the message-boards message
815             * @return the message-boards message that was removed
816             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
817             * @throws SystemException if a system exception occurred
818             */
819            public MBMessage remove(long messageId)
820                    throws NoSuchMessageException, SystemException {
821                    return remove(Long.valueOf(messageId));
822            }
823    
824            /**
825             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
826             *
827             * @param primaryKey the primary key of the message-boards message
828             * @return the message-boards message that was removed
829             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
830             * @throws SystemException if a system exception occurred
831             */
832            @Override
833            public MBMessage remove(Serializable primaryKey)
834                    throws NoSuchMessageException, SystemException {
835                    Session session = null;
836    
837                    try {
838                            session = openSession();
839    
840                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
841                                            primaryKey);
842    
843                            if (mbMessage == null) {
844                                    if (_log.isWarnEnabled()) {
845                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
846                                    }
847    
848                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
849                                            primaryKey);
850                            }
851    
852                            return remove(mbMessage);
853                    }
854                    catch (NoSuchMessageException nsee) {
855                            throw nsee;
856                    }
857                    catch (Exception e) {
858                            throw processException(e);
859                    }
860                    finally {
861                            closeSession(session);
862                    }
863            }
864    
865            @Override
866            protected MBMessage removeImpl(MBMessage mbMessage)
867                    throws SystemException {
868                    mbMessage = toUnwrappedModel(mbMessage);
869    
870                    Session session = null;
871    
872                    try {
873                            session = openSession();
874    
875                            if (mbMessage.isCachedModel()) {
876                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
877                                                    mbMessage.getPrimaryKeyObj());
878                            }
879    
880                            session.delete(mbMessage);
881                    }
882                    catch (Exception e) {
883                            throw processException(e);
884                    }
885                    finally {
886                            closeSession(session);
887                    }
888    
889                    clearCache(mbMessage);
890    
891                    return mbMessage;
892            }
893    
894            @Override
895            public MBMessage updateImpl(
896                    com.liferay.portlet.messageboards.model.MBMessage mbMessage)
897                    throws SystemException {
898                    mbMessage = toUnwrappedModel(mbMessage);
899    
900                    boolean isNew = mbMessage.isNew();
901    
902                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
903    
904                    if (Validator.isNull(mbMessage.getUuid())) {
905                            String uuid = PortalUUIDUtil.generate();
906    
907                            mbMessage.setUuid(uuid);
908                    }
909    
910                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
911    
912                    if (userId > 0) {
913                            long companyId = mbMessage.getCompanyId();
914    
915                            long groupId = mbMessage.getGroupId();
916    
917                            long messageId = 0;
918    
919                            if (!isNew) {
920                                    messageId = mbMessage.getPrimaryKey();
921                            }
922    
923                            try {
924                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
925                                                    userId,
926                                                    com.liferay.portlet.messageboards.model.MBMessage.class.getName(),
927                                                    messageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
928                                                    mbMessage.getSubject(), null));
929                            }
930                            catch (SanitizerException se) {
931                                    throw new SystemException(se);
932                            }
933                    }
934    
935                    Session session = null;
936    
937                    try {
938                            session = openSession();
939    
940                            if (mbMessage.isNew()) {
941                                    session.save(mbMessage);
942    
943                                    mbMessage.setNew(false);
944                            }
945                            else {
946                                    session.merge(mbMessage);
947                            }
948                    }
949                    catch (Exception e) {
950                            throw processException(e);
951                    }
952                    finally {
953                            closeSession(session);
954                    }
955    
956                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
957    
958                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
959                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
960                    }
961    
962                    else {
963                            if ((mbMessageModelImpl.getColumnBitmask() &
964                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
965                                    Object[] args = new Object[] {
966                                                    mbMessageModelImpl.getOriginalUuid()
967                                            };
968    
969                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
970                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
971                                            args);
972    
973                                    args = new Object[] { mbMessageModelImpl.getUuid() };
974    
975                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
976                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
977                                            args);
978                            }
979    
980                            if ((mbMessageModelImpl.getColumnBitmask() &
981                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
982                                    Object[] args = new Object[] {
983                                                    mbMessageModelImpl.getOriginalUuid(),
984                                                    Long.valueOf(mbMessageModelImpl.getOriginalCompanyId())
985                                            };
986    
987                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
988                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
989                                            args);
990    
991                                    args = new Object[] {
992                                                    mbMessageModelImpl.getUuid(),
993                                                    Long.valueOf(mbMessageModelImpl.getCompanyId())
994                                            };
995    
996                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
997                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
998                                            args);
999                            }
1000    
1001                            if ((mbMessageModelImpl.getColumnBitmask() &
1002                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
1003                                    Object[] args = new Object[] {
1004                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId())
1005                                            };
1006    
1007                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1008                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1009                                            args);
1010    
1011                                    args = new Object[] {
1012                                                    Long.valueOf(mbMessageModelImpl.getGroupId())
1013                                            };
1014    
1015                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1016                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1017                                            args);
1018                            }
1019    
1020                            if ((mbMessageModelImpl.getColumnBitmask() &
1021                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
1022                                    Object[] args = new Object[] {
1023                                                    Long.valueOf(mbMessageModelImpl.getOriginalCompanyId())
1024                                            };
1025    
1026                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1027                                            args);
1028                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1029                                            args);
1030    
1031                                    args = new Object[] {
1032                                                    Long.valueOf(mbMessageModelImpl.getCompanyId())
1033                                            };
1034    
1035                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1036                                            args);
1037                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1038                                            args);
1039                            }
1040    
1041                            if ((mbMessageModelImpl.getColumnBitmask() &
1042                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
1043                                    Object[] args = new Object[] {
1044                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
1045                                            };
1046    
1047                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
1048                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
1049                                            args);
1050    
1051                                    args = new Object[] {
1052                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
1053                                            };
1054    
1055                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
1056                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
1057                                            args);
1058                            }
1059    
1060                            if ((mbMessageModelImpl.getColumnBitmask() &
1061                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
1062                                    Object[] args = new Object[] {
1063                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
1064                                            };
1065    
1066                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
1067                                            args);
1068                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
1069                                            args);
1070    
1071                                    args = new Object[] {
1072                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
1073                                            };
1074    
1075                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
1076                                            args);
1077                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
1078                                            args);
1079                            }
1080    
1081                            if ((mbMessageModelImpl.getColumnBitmask() &
1082                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1083                                    Object[] args = new Object[] {
1084                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId())
1085                                            };
1086    
1087                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1088                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1089                                            args);
1090    
1091                                    args = new Object[] { Long.valueOf(mbMessageModelImpl.getUserId()) };
1092    
1093                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1094                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1095                                            args);
1096                            }
1097    
1098                            if ((mbMessageModelImpl.getColumnBitmask() &
1099                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
1100                                    Object[] args = new Object[] {
1101                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1102                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId())
1103                                            };
1104    
1105                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
1106                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
1107                                            args);
1108    
1109                                    args = new Object[] {
1110                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1111                                                    Long.valueOf(mbMessageModelImpl.getUserId())
1112                                            };
1113    
1114                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
1115                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
1116                                            args);
1117                            }
1118    
1119                            if ((mbMessageModelImpl.getColumnBitmask() &
1120                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
1121                                    Object[] args = new Object[] {
1122                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1123                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId())
1124                                            };
1125    
1126                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
1127                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
1128                                            args);
1129    
1130                                    args = new Object[] {
1131                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1132                                                    Long.valueOf(mbMessageModelImpl.getCategoryId())
1133                                            };
1134    
1135                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
1136                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
1137                                            args);
1138                            }
1139    
1140                            if ((mbMessageModelImpl.getColumnBitmask() &
1141                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
1142                                    Object[] args = new Object[] {
1143                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1144                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1145                                            };
1146    
1147                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
1148                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
1149                                            args);
1150    
1151                                    args = new Object[] {
1152                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1153                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1154                                            };
1155    
1156                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
1157                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
1158                                            args);
1159                            }
1160    
1161                            if ((mbMessageModelImpl.getColumnBitmask() &
1162                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
1163                                    Object[] args = new Object[] {
1164                                                    Long.valueOf(mbMessageModelImpl.getOriginalCompanyId()),
1165                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1166                                            };
1167    
1168                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
1169                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
1170                                            args);
1171    
1172                                    args = new Object[] {
1173                                                    Long.valueOf(mbMessageModelImpl.getCompanyId()),
1174                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1175                                            };
1176    
1177                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
1178                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
1179                                            args);
1180                            }
1181    
1182                            if ((mbMessageModelImpl.getColumnBitmask() &
1183                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
1184                                    Object[] args = new Object[] {
1185                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1186                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId())
1187                                            };
1188    
1189                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
1190                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
1191                                            args);
1192    
1193                                    args = new Object[] {
1194                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1195                                                    Long.valueOf(mbMessageModelImpl.getClassNameId())
1196                                            };
1197    
1198                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
1199                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
1200                                            args);
1201                            }
1202    
1203                            if ((mbMessageModelImpl.getColumnBitmask() &
1204                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
1205                                    Object[] args = new Object[] {
1206                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1207                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK())
1208                                            };
1209    
1210                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1211                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1212                                            args);
1213    
1214                                    args = new Object[] {
1215                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1216                                                    Long.valueOf(mbMessageModelImpl.getClassPK())
1217                                            };
1218    
1219                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1220                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1221                                            args);
1222                            }
1223    
1224                            if ((mbMessageModelImpl.getColumnBitmask() &
1225                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
1226                                    Object[] args = new Object[] {
1227                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1228                                                    Long.valueOf(mbMessageModelImpl.getOriginalParentMessageId())
1229                                            };
1230    
1231                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
1232                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
1233                                            args);
1234    
1235                                    args = new Object[] {
1236                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1237                                                    Long.valueOf(mbMessageModelImpl.getParentMessageId())
1238                                            };
1239    
1240                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
1241                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
1242                                            args);
1243                            }
1244    
1245                            if ((mbMessageModelImpl.getColumnBitmask() &
1246                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
1247                                    Object[] args = new Object[] {
1248                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1249                                                    Boolean.valueOf(mbMessageModelImpl.getOriginalAnswer())
1250                                            };
1251    
1252                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
1253                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
1254                                            args);
1255    
1256                                    args = new Object[] {
1257                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1258                                                    Boolean.valueOf(mbMessageModelImpl.getAnswer())
1259                                            };
1260    
1261                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
1262                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
1263                                            args);
1264                            }
1265    
1266                            if ((mbMessageModelImpl.getColumnBitmask() &
1267                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
1268                                    Object[] args = new Object[] {
1269                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1270                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1271                                            };
1272    
1273                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
1274                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
1275                                            args);
1276    
1277                                    args = new Object[] {
1278                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1279                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1280                                            };
1281    
1282                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
1283                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
1284                                            args);
1285                            }
1286    
1287                            if ((mbMessageModelImpl.getColumnBitmask() &
1288                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
1289                                    Object[] args = new Object[] {
1290                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1291                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1292                                            };
1293    
1294                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
1295                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
1296                                            args);
1297    
1298                                    args = new Object[] {
1299                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1300                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1301                                            };
1302    
1303                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
1304                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
1305                                            args);
1306                            }
1307    
1308                            if ((mbMessageModelImpl.getColumnBitmask() &
1309                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
1310                                    Object[] args = new Object[] {
1311                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1312                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1313                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1314                                            };
1315    
1316                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
1317                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
1318                                            args);
1319    
1320                                    args = new Object[] {
1321                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1322                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1323                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1324                                            };
1325    
1326                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
1327                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
1328                                            args);
1329                            }
1330    
1331                            if ((mbMessageModelImpl.getColumnBitmask() &
1332                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
1333                                    Object[] args = new Object[] {
1334                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1335                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1336                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
1337                                            };
1338    
1339                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
1340                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
1341                                            args);
1342    
1343                                    args = new Object[] {
1344                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1345                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1346                                                    Long.valueOf(mbMessageModelImpl.getThreadId())
1347                                            };
1348    
1349                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
1350                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
1351                                            args);
1352                            }
1353    
1354                            if ((mbMessageModelImpl.getColumnBitmask() &
1355                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
1356                                    Object[] args = new Object[] {
1357                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1358                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1359                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1360                                            };
1361    
1362                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
1363                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
1364                                            args);
1365    
1366                                    args = new Object[] {
1367                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1368                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1369                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1370                                            };
1371    
1372                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
1373                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
1374                                            args);
1375                            }
1376    
1377                            if ((mbMessageModelImpl.getColumnBitmask() &
1378                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
1379                                    Object[] args = new Object[] {
1380                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1381                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1382                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK())
1383                                            };
1384    
1385                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
1386                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
1387                                            args);
1388    
1389                                    args = new Object[] {
1390                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1391                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1392                                                    Long.valueOf(mbMessageModelImpl.getClassPK())
1393                                            };
1394    
1395                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
1396                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
1397                                            args);
1398                            }
1399    
1400                            if ((mbMessageModelImpl.getColumnBitmask() &
1401                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
1402                                    Object[] args = new Object[] {
1403                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1404                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1405                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1406                                            };
1407    
1408                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
1409                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
1410                                            args);
1411    
1412                                    args = new Object[] {
1413                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1414                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1415                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1416                                            };
1417    
1418                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
1419                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
1420                                            args);
1421                            }
1422    
1423                            if ((mbMessageModelImpl.getColumnBitmask() &
1424                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
1425                                    Object[] args = new Object[] {
1426                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1427                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK()),
1428                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1429                                            };
1430    
1431                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
1432                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
1433                                            args);
1434    
1435                                    args = new Object[] {
1436                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1437                                                    Long.valueOf(mbMessageModelImpl.getClassPK()),
1438                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1439                                            };
1440    
1441                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
1442                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
1443                                            args);
1444                            }
1445    
1446                            if ((mbMessageModelImpl.getColumnBitmask() &
1447                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
1448                                    Object[] args = new Object[] {
1449                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1450                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1451                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1452                                                    Boolean.valueOf(mbMessageModelImpl.getOriginalAnswer())
1453                                            };
1454    
1455                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
1456                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
1457                                            args);
1458    
1459                                    args = new Object[] {
1460                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1461                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1462                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1463                                                    Boolean.valueOf(mbMessageModelImpl.getAnswer())
1464                                            };
1465    
1466                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
1467                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
1468                                            args);
1469                            }
1470    
1471                            if ((mbMessageModelImpl.getColumnBitmask() &
1472                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
1473                                    Object[] args = new Object[] {
1474                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
1475                                                    Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
1476                                                    Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
1477                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1478                                            };
1479    
1480                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
1481                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
1482                                            args);
1483    
1484                                    args = new Object[] {
1485                                                    Long.valueOf(mbMessageModelImpl.getGroupId()),
1486                                                    Long.valueOf(mbMessageModelImpl.getCategoryId()),
1487                                                    Long.valueOf(mbMessageModelImpl.getThreadId()),
1488                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1489                                            };
1490    
1491                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
1492                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
1493                                            args);
1494                            }
1495    
1496                            if ((mbMessageModelImpl.getColumnBitmask() &
1497                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
1498                                    Object[] args = new Object[] {
1499                                                    Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
1500                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
1501                                                    Long.valueOf(mbMessageModelImpl.getOriginalClassPK()),
1502                                                    Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
1503                                            };
1504    
1505                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
1506                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
1507                                            args);
1508    
1509                                    args = new Object[] {
1510                                                    Long.valueOf(mbMessageModelImpl.getUserId()),
1511                                                    Long.valueOf(mbMessageModelImpl.getClassNameId()),
1512                                                    Long.valueOf(mbMessageModelImpl.getClassPK()),
1513                                                    Integer.valueOf(mbMessageModelImpl.getStatus())
1514                                            };
1515    
1516                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
1517                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
1518                                            args);
1519                            }
1520                    }
1521    
1522                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1523                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
1524    
1525                    if (isNew) {
1526                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1527                                    new Object[] {
1528                                            mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
1529                                    }, mbMessage);
1530                    }
1531                    else {
1532                            if ((mbMessageModelImpl.getColumnBitmask() &
1533                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
1534                                    Object[] args = new Object[] {
1535                                                    mbMessageModelImpl.getOriginalUuid(),
1536                                                    Long.valueOf(mbMessageModelImpl.getOriginalGroupId())
1537                                            };
1538    
1539                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
1540    
1541                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
1542    
1543                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1544                                            new Object[] {
1545                                                    mbMessage.getUuid(),
1546                                                    Long.valueOf(mbMessage.getGroupId())
1547                                            }, mbMessage);
1548                            }
1549                    }
1550    
1551                    return mbMessage;
1552            }
1553    
1554            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
1555                    if (mbMessage instanceof MBMessageImpl) {
1556                            return mbMessage;
1557                    }
1558    
1559                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
1560    
1561                    mbMessageImpl.setNew(mbMessage.isNew());
1562                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
1563    
1564                    mbMessageImpl.setUuid(mbMessage.getUuid());
1565                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
1566                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
1567                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
1568                    mbMessageImpl.setUserId(mbMessage.getUserId());
1569                    mbMessageImpl.setUserName(mbMessage.getUserName());
1570                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
1571                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
1572                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
1573                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
1574                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
1575                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
1576                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
1577                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
1578                    mbMessageImpl.setSubject(mbMessage.getSubject());
1579                    mbMessageImpl.setBody(mbMessage.getBody());
1580                    mbMessageImpl.setFormat(mbMessage.getFormat());
1581                    mbMessageImpl.setAttachments(mbMessage.isAttachments());
1582                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
1583                    mbMessageImpl.setPriority(mbMessage.getPriority());
1584                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
1585                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
1586                    mbMessageImpl.setStatus(mbMessage.getStatus());
1587                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
1588                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
1589                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
1590    
1591                    return mbMessageImpl;
1592            }
1593    
1594            /**
1595             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1596             *
1597             * @param primaryKey the primary key of the message-boards message
1598             * @return the message-boards message
1599             * @throws com.liferay.portal.NoSuchModelException if a message-boards message with the primary key could not be found
1600             * @throws SystemException if a system exception occurred
1601             */
1602            @Override
1603            public MBMessage findByPrimaryKey(Serializable primaryKey)
1604                    throws NoSuchModelException, SystemException {
1605                    return findByPrimaryKey(((Long)primaryKey).longValue());
1606            }
1607    
1608            /**
1609             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchMessageException} if it could not be found.
1610             *
1611             * @param messageId the primary key of the message-boards message
1612             * @return the message-boards message
1613             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1614             * @throws SystemException if a system exception occurred
1615             */
1616            public MBMessage findByPrimaryKey(long messageId)
1617                    throws NoSuchMessageException, SystemException {
1618                    MBMessage mbMessage = fetchByPrimaryKey(messageId);
1619    
1620                    if (mbMessage == null) {
1621                            if (_log.isWarnEnabled()) {
1622                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageId);
1623                            }
1624    
1625                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1626                                    messageId);
1627                    }
1628    
1629                    return mbMessage;
1630            }
1631    
1632            /**
1633             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
1634             *
1635             * @param primaryKey the primary key of the message-boards message
1636             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
1637             * @throws SystemException if a system exception occurred
1638             */
1639            @Override
1640            public MBMessage fetchByPrimaryKey(Serializable primaryKey)
1641                    throws SystemException {
1642                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
1643            }
1644    
1645            /**
1646             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
1647             *
1648             * @param messageId the primary key of the message-boards message
1649             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
1650             * @throws SystemException if a system exception occurred
1651             */
1652            public MBMessage fetchByPrimaryKey(long messageId)
1653                    throws SystemException {
1654                    MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1655                                    MBMessageImpl.class, messageId);
1656    
1657                    if (mbMessage == _nullMBMessage) {
1658                            return null;
1659                    }
1660    
1661                    if (mbMessage == null) {
1662                            Session session = null;
1663    
1664                            boolean hasException = false;
1665    
1666                            try {
1667                                    session = openSession();
1668    
1669                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
1670                                                    Long.valueOf(messageId));
1671                            }
1672                            catch (Exception e) {
1673                                    hasException = true;
1674    
1675                                    throw processException(e);
1676                            }
1677                            finally {
1678                                    if (mbMessage != null) {
1679                                            cacheResult(mbMessage);
1680                                    }
1681                                    else if (!hasException) {
1682                                            EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1683                                                    MBMessageImpl.class, messageId, _nullMBMessage);
1684                                    }
1685    
1686                                    closeSession(session);
1687                            }
1688                    }
1689    
1690                    return mbMessage;
1691            }
1692    
1693            /**
1694             * Returns all the message-boards messages where uuid = &#63;.
1695             *
1696             * @param uuid the uuid
1697             * @return the matching message-boards messages
1698             * @throws SystemException if a system exception occurred
1699             */
1700            public List<MBMessage> findByUuid(String uuid) throws SystemException {
1701                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1702            }
1703    
1704            /**
1705             * Returns a range of all the message-boards messages where uuid = &#63;.
1706             *
1707             * <p>
1708             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1709             * </p>
1710             *
1711             * @param uuid the uuid
1712             * @param start the lower bound of the range of message-boards messages
1713             * @param end the upper bound of the range of message-boards messages (not inclusive)
1714             * @return the range of matching message-boards messages
1715             * @throws SystemException if a system exception occurred
1716             */
1717            public List<MBMessage> findByUuid(String uuid, int start, int end)
1718                    throws SystemException {
1719                    return findByUuid(uuid, start, end, null);
1720            }
1721    
1722            /**
1723             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
1724             *
1725             * <p>
1726             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1727             * </p>
1728             *
1729             * @param uuid the uuid
1730             * @param start the lower bound of the range of message-boards messages
1731             * @param end the upper bound of the range of message-boards messages (not inclusive)
1732             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1733             * @return the ordered range of matching message-boards messages
1734             * @throws SystemException if a system exception occurred
1735             */
1736            public List<MBMessage> findByUuid(String uuid, int start, int end,
1737                    OrderByComparator orderByComparator) throws SystemException {
1738                    FinderPath finderPath = null;
1739                    Object[] finderArgs = null;
1740    
1741                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1742                                    (orderByComparator == null)) {
1743                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
1744                            finderArgs = new Object[] { uuid };
1745                    }
1746                    else {
1747                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
1748                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
1749                    }
1750    
1751                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
1752                                    finderArgs, this);
1753    
1754                    if ((list != null) && !list.isEmpty()) {
1755                            for (MBMessage mbMessage : list) {
1756                                    if (!Validator.equals(uuid, mbMessage.getUuid())) {
1757                                            list = null;
1758    
1759                                            break;
1760                                    }
1761                            }
1762                    }
1763    
1764                    if (list == null) {
1765                            StringBundler query = null;
1766    
1767                            if (orderByComparator != null) {
1768                                    query = new StringBundler(3 +
1769                                                    (orderByComparator.getOrderByFields().length * 3));
1770                            }
1771                            else {
1772                                    query = new StringBundler(3);
1773                            }
1774    
1775                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1776    
1777                            if (uuid == null) {
1778                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1779                            }
1780                            else {
1781                                    if (uuid.equals(StringPool.BLANK)) {
1782                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1783                                    }
1784                                    else {
1785                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1786                                    }
1787                            }
1788    
1789                            if (orderByComparator != null) {
1790                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1791                                            orderByComparator);
1792                            }
1793    
1794                            else {
1795                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1796                            }
1797    
1798                            String sql = query.toString();
1799    
1800                            Session session = null;
1801    
1802                            try {
1803                                    session = openSession();
1804    
1805                                    Query q = session.createQuery(sql);
1806    
1807                                    QueryPos qPos = QueryPos.getInstance(q);
1808    
1809                                    if (uuid != null) {
1810                                            qPos.add(uuid);
1811                                    }
1812    
1813                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
1814                                                    end);
1815                            }
1816                            catch (Exception e) {
1817                                    throw processException(e);
1818                            }
1819                            finally {
1820                                    if (list == null) {
1821                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1822                                    }
1823                                    else {
1824                                            cacheResult(list);
1825    
1826                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1827                                    }
1828    
1829                                    closeSession(session);
1830                            }
1831                    }
1832    
1833                    return list;
1834            }
1835    
1836            /**
1837             * Returns the first message-boards message in the ordered set where uuid = &#63;.
1838             *
1839             * @param uuid the uuid
1840             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1841             * @return the first matching message-boards message
1842             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1843             * @throws SystemException if a system exception occurred
1844             */
1845            public MBMessage findByUuid_First(String uuid,
1846                    OrderByComparator orderByComparator)
1847                    throws NoSuchMessageException, SystemException {
1848                    MBMessage mbMessage = fetchByUuid_First(uuid, orderByComparator);
1849    
1850                    if (mbMessage != null) {
1851                            return mbMessage;
1852                    }
1853    
1854                    StringBundler msg = new StringBundler(4);
1855    
1856                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1857    
1858                    msg.append("uuid=");
1859                    msg.append(uuid);
1860    
1861                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1862    
1863                    throw new NoSuchMessageException(msg.toString());
1864            }
1865    
1866            /**
1867             * Returns the first message-boards message in the ordered set where uuid = &#63;.
1868             *
1869             * @param uuid the uuid
1870             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1871             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1872             * @throws SystemException if a system exception occurred
1873             */
1874            public MBMessage fetchByUuid_First(String uuid,
1875                    OrderByComparator orderByComparator) throws SystemException {
1876                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
1877    
1878                    if (!list.isEmpty()) {
1879                            return list.get(0);
1880                    }
1881    
1882                    return null;
1883            }
1884    
1885            /**
1886             * Returns the last message-boards message in the ordered set where uuid = &#63;.
1887             *
1888             * @param uuid the uuid
1889             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1890             * @return the last matching message-boards message
1891             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1892             * @throws SystemException if a system exception occurred
1893             */
1894            public MBMessage findByUuid_Last(String uuid,
1895                    OrderByComparator orderByComparator)
1896                    throws NoSuchMessageException, SystemException {
1897                    MBMessage mbMessage = fetchByUuid_Last(uuid, orderByComparator);
1898    
1899                    if (mbMessage != null) {
1900                            return mbMessage;
1901                    }
1902    
1903                    StringBundler msg = new StringBundler(4);
1904    
1905                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1906    
1907                    msg.append("uuid=");
1908                    msg.append(uuid);
1909    
1910                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1911    
1912                    throw new NoSuchMessageException(msg.toString());
1913            }
1914    
1915            /**
1916             * Returns the last message-boards message in the ordered set where uuid = &#63;.
1917             *
1918             * @param uuid the uuid
1919             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1920             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1921             * @throws SystemException if a system exception occurred
1922             */
1923            public MBMessage fetchByUuid_Last(String uuid,
1924                    OrderByComparator orderByComparator) throws SystemException {
1925                    int count = countByUuid(uuid);
1926    
1927                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
1928                                    orderByComparator);
1929    
1930                    if (!list.isEmpty()) {
1931                            return list.get(0);
1932                    }
1933    
1934                    return null;
1935            }
1936    
1937            /**
1938             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
1939             *
1940             * @param messageId the primary key of the current message-boards message
1941             * @param uuid the uuid
1942             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1943             * @return the previous, current, and next message-boards message
1944             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1945             * @throws SystemException if a system exception occurred
1946             */
1947            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
1948                    OrderByComparator orderByComparator)
1949                    throws NoSuchMessageException, SystemException {
1950                    MBMessage mbMessage = findByPrimaryKey(messageId);
1951    
1952                    Session session = null;
1953    
1954                    try {
1955                            session = openSession();
1956    
1957                            MBMessage[] array = new MBMessageImpl[3];
1958    
1959                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
1960                                            orderByComparator, true);
1961    
1962                            array[1] = mbMessage;
1963    
1964                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
1965                                            orderByComparator, false);
1966    
1967                            return array;
1968                    }
1969                    catch (Exception e) {
1970                            throw processException(e);
1971                    }
1972                    finally {
1973                            closeSession(session);
1974                    }
1975            }
1976    
1977            protected MBMessage getByUuid_PrevAndNext(Session session,
1978                    MBMessage mbMessage, String uuid, OrderByComparator orderByComparator,
1979                    boolean previous) {
1980                    StringBundler query = null;
1981    
1982                    if (orderByComparator != null) {
1983                            query = new StringBundler(6 +
1984                                            (orderByComparator.getOrderByFields().length * 6));
1985                    }
1986                    else {
1987                            query = new StringBundler(3);
1988                    }
1989    
1990                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1991    
1992                    if (uuid == null) {
1993                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1994                    }
1995                    else {
1996                            if (uuid.equals(StringPool.BLANK)) {
1997                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1998                            }
1999                            else {
2000                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
2001                            }
2002                    }
2003    
2004                    if (orderByComparator != null) {
2005                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2006    
2007                            if (orderByConditionFields.length > 0) {
2008                                    query.append(WHERE_AND);
2009                            }
2010    
2011                            for (int i = 0; i < orderByConditionFields.length; i++) {
2012                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2013                                    query.append(orderByConditionFields[i]);
2014    
2015                                    if ((i + 1) < orderByConditionFields.length) {
2016                                            if (orderByComparator.isAscending() ^ previous) {
2017                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2018                                            }
2019                                            else {
2020                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2021                                            }
2022                                    }
2023                                    else {
2024                                            if (orderByComparator.isAscending() ^ previous) {
2025                                                    query.append(WHERE_GREATER_THAN);
2026                                            }
2027                                            else {
2028                                                    query.append(WHERE_LESSER_THAN);
2029                                            }
2030                                    }
2031                            }
2032    
2033                            query.append(ORDER_BY_CLAUSE);
2034    
2035                            String[] orderByFields = orderByComparator.getOrderByFields();
2036    
2037                            for (int i = 0; i < orderByFields.length; i++) {
2038                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2039                                    query.append(orderByFields[i]);
2040    
2041                                    if ((i + 1) < orderByFields.length) {
2042                                            if (orderByComparator.isAscending() ^ previous) {
2043                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2044                                            }
2045                                            else {
2046                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2047                                            }
2048                                    }
2049                                    else {
2050                                            if (orderByComparator.isAscending() ^ previous) {
2051                                                    query.append(ORDER_BY_ASC);
2052                                            }
2053                                            else {
2054                                                    query.append(ORDER_BY_DESC);
2055                                            }
2056                                    }
2057                            }
2058                    }
2059    
2060                    else {
2061                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2062                    }
2063    
2064                    String sql = query.toString();
2065    
2066                    Query q = session.createQuery(sql);
2067    
2068                    q.setFirstResult(0);
2069                    q.setMaxResults(2);
2070    
2071                    QueryPos qPos = QueryPos.getInstance(q);
2072    
2073                    if (uuid != null) {
2074                            qPos.add(uuid);
2075                    }
2076    
2077                    if (orderByComparator != null) {
2078                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2079    
2080                            for (Object value : values) {
2081                                    qPos.add(value);
2082                            }
2083                    }
2084    
2085                    List<MBMessage> list = q.list();
2086    
2087                    if (list.size() == 2) {
2088                            return list.get(1);
2089                    }
2090                    else {
2091                            return null;
2092                    }
2093            }
2094    
2095            /**
2096             * 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.
2097             *
2098             * @param uuid the uuid
2099             * @param groupId the group ID
2100             * @return the matching message-boards message
2101             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2102             * @throws SystemException if a system exception occurred
2103             */
2104            public MBMessage findByUUID_G(String uuid, long groupId)
2105                    throws NoSuchMessageException, SystemException {
2106                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
2107    
2108                    if (mbMessage == null) {
2109                            StringBundler msg = new StringBundler(6);
2110    
2111                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2112    
2113                            msg.append("uuid=");
2114                            msg.append(uuid);
2115    
2116                            msg.append(", groupId=");
2117                            msg.append(groupId);
2118    
2119                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2120    
2121                            if (_log.isWarnEnabled()) {
2122                                    _log.warn(msg.toString());
2123                            }
2124    
2125                            throw new NoSuchMessageException(msg.toString());
2126                    }
2127    
2128                    return mbMessage;
2129            }
2130    
2131            /**
2132             * 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.
2133             *
2134             * @param uuid the uuid
2135             * @param groupId the group ID
2136             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2137             * @throws SystemException if a system exception occurred
2138             */
2139            public MBMessage fetchByUUID_G(String uuid, long groupId)
2140                    throws SystemException {
2141                    return fetchByUUID_G(uuid, groupId, true);
2142            }
2143    
2144            /**
2145             * 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.
2146             *
2147             * @param uuid the uuid
2148             * @param groupId the group ID
2149             * @param retrieveFromCache whether to use the finder cache
2150             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2151             * @throws SystemException if a system exception occurred
2152             */
2153            public MBMessage fetchByUUID_G(String uuid, long groupId,
2154                    boolean retrieveFromCache) throws SystemException {
2155                    Object[] finderArgs = new Object[] { uuid, groupId };
2156    
2157                    Object result = null;
2158    
2159                    if (retrieveFromCache) {
2160                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
2161                                            finderArgs, this);
2162                    }
2163    
2164                    if (result instanceof MBMessage) {
2165                            MBMessage mbMessage = (MBMessage)result;
2166    
2167                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
2168                                            (groupId != mbMessage.getGroupId())) {
2169                                    result = null;
2170                            }
2171                    }
2172    
2173                    if (result == null) {
2174                            StringBundler query = new StringBundler(4);
2175    
2176                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2177    
2178                            if (uuid == null) {
2179                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2180                            }
2181                            else {
2182                                    if (uuid.equals(StringPool.BLANK)) {
2183                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2184                                    }
2185                                    else {
2186                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2187                                    }
2188                            }
2189    
2190                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2191    
2192                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2193    
2194                            String sql = query.toString();
2195    
2196                            Session session = null;
2197    
2198                            try {
2199                                    session = openSession();
2200    
2201                                    Query q = session.createQuery(sql);
2202    
2203                                    QueryPos qPos = QueryPos.getInstance(q);
2204    
2205                                    if (uuid != null) {
2206                                            qPos.add(uuid);
2207                                    }
2208    
2209                                    qPos.add(groupId);
2210    
2211                                    List<MBMessage> list = q.list();
2212    
2213                                    result = list;
2214    
2215                                    MBMessage mbMessage = null;
2216    
2217                                    if (list.isEmpty()) {
2218                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2219                                                    finderArgs, list);
2220                                    }
2221                                    else {
2222                                            mbMessage = list.get(0);
2223    
2224                                            cacheResult(mbMessage);
2225    
2226                                            if ((mbMessage.getUuid() == null) ||
2227                                                            !mbMessage.getUuid().equals(uuid) ||
2228                                                            (mbMessage.getGroupId() != groupId)) {
2229                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2230                                                            finderArgs, mbMessage);
2231                                            }
2232                                    }
2233    
2234                                    return mbMessage;
2235                            }
2236                            catch (Exception e) {
2237                                    throw processException(e);
2238                            }
2239                            finally {
2240                                    if (result == null) {
2241                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
2242                                                    finderArgs);
2243                                    }
2244    
2245                                    closeSession(session);
2246                            }
2247                    }
2248                    else {
2249                            if (result instanceof List<?>) {
2250                                    return null;
2251                            }
2252                            else {
2253                                    return (MBMessage)result;
2254                            }
2255                    }
2256            }
2257    
2258            /**
2259             * Returns all the message-boards messages where uuid = &#63; and companyId = &#63;.
2260             *
2261             * @param uuid the uuid
2262             * @param companyId the company ID
2263             * @return the matching message-boards messages
2264             * @throws SystemException if a system exception occurred
2265             */
2266            public List<MBMessage> findByUuid_C(String uuid, long companyId)
2267                    throws SystemException {
2268                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
2269                            QueryUtil.ALL_POS, null);
2270            }
2271    
2272            /**
2273             * Returns a range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
2274             *
2275             * <p>
2276             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2277             * </p>
2278             *
2279             * @param uuid the uuid
2280             * @param companyId the company ID
2281             * @param start the lower bound of the range of message-boards messages
2282             * @param end the upper bound of the range of message-boards messages (not inclusive)
2283             * @return the range of matching message-boards messages
2284             * @throws SystemException if a system exception occurred
2285             */
2286            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
2287                    int end) throws SystemException {
2288                    return findByUuid_C(uuid, companyId, start, end, null);
2289            }
2290    
2291            /**
2292             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
2293             *
2294             * <p>
2295             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2296             * </p>
2297             *
2298             * @param uuid the uuid
2299             * @param companyId the company ID
2300             * @param start the lower bound of the range of message-boards messages
2301             * @param end the upper bound of the range of message-boards messages (not inclusive)
2302             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2303             * @return the ordered range of matching message-boards messages
2304             * @throws SystemException if a system exception occurred
2305             */
2306            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
2307                    int end, OrderByComparator orderByComparator) throws SystemException {
2308                    FinderPath finderPath = null;
2309                    Object[] finderArgs = null;
2310    
2311                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2312                                    (orderByComparator == null)) {
2313                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
2314                            finderArgs = new Object[] { uuid, companyId };
2315                    }
2316                    else {
2317                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
2318                            finderArgs = new Object[] {
2319                                            uuid, companyId,
2320                                            
2321                                            start, end, orderByComparator
2322                                    };
2323                    }
2324    
2325                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2326                                    finderArgs, this);
2327    
2328                    if ((list != null) && !list.isEmpty()) {
2329                            for (MBMessage mbMessage : list) {
2330                                    if (!Validator.equals(uuid, mbMessage.getUuid()) ||
2331                                                    (companyId != mbMessage.getCompanyId())) {
2332                                            list = null;
2333    
2334                                            break;
2335                                    }
2336                            }
2337                    }
2338    
2339                    if (list == null) {
2340                            StringBundler query = null;
2341    
2342                            if (orderByComparator != null) {
2343                                    query = new StringBundler(4 +
2344                                                    (orderByComparator.getOrderByFields().length * 3));
2345                            }
2346                            else {
2347                                    query = new StringBundler(4);
2348                            }
2349    
2350                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2351    
2352                            if (uuid == null) {
2353                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
2354                            }
2355                            else {
2356                                    if (uuid.equals(StringPool.BLANK)) {
2357                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
2358                                    }
2359                                    else {
2360                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
2361                                    }
2362                            }
2363    
2364                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
2365    
2366                            if (orderByComparator != null) {
2367                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2368                                            orderByComparator);
2369                            }
2370    
2371                            else {
2372                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2373                            }
2374    
2375                            String sql = query.toString();
2376    
2377                            Session session = null;
2378    
2379                            try {
2380                                    session = openSession();
2381    
2382                                    Query q = session.createQuery(sql);
2383    
2384                                    QueryPos qPos = QueryPos.getInstance(q);
2385    
2386                                    if (uuid != null) {
2387                                            qPos.add(uuid);
2388                                    }
2389    
2390                                    qPos.add(companyId);
2391    
2392                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2393                                                    end);
2394                            }
2395                            catch (Exception e) {
2396                                    throw processException(e);
2397                            }
2398                            finally {
2399                                    if (list == null) {
2400                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2401                                    }
2402                                    else {
2403                                            cacheResult(list);
2404    
2405                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2406                                    }
2407    
2408                                    closeSession(session);
2409                            }
2410                    }
2411    
2412                    return list;
2413            }
2414    
2415            /**
2416             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
2417             *
2418             * @param uuid the uuid
2419             * @param companyId the company ID
2420             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2421             * @return the first matching message-boards message
2422             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2423             * @throws SystemException if a system exception occurred
2424             */
2425            public MBMessage findByUuid_C_First(String uuid, long companyId,
2426                    OrderByComparator orderByComparator)
2427                    throws NoSuchMessageException, SystemException {
2428                    MBMessage mbMessage = fetchByUuid_C_First(uuid, companyId,
2429                                    orderByComparator);
2430    
2431                    if (mbMessage != null) {
2432                            return mbMessage;
2433                    }
2434    
2435                    StringBundler msg = new StringBundler(6);
2436    
2437                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2438    
2439                    msg.append("uuid=");
2440                    msg.append(uuid);
2441    
2442                    msg.append(", companyId=");
2443                    msg.append(companyId);
2444    
2445                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2446    
2447                    throw new NoSuchMessageException(msg.toString());
2448            }
2449    
2450            /**
2451             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
2452             *
2453             * @param uuid the uuid
2454             * @param companyId the company ID
2455             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2456             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2457             * @throws SystemException if a system exception occurred
2458             */
2459            public MBMessage fetchByUuid_C_First(String uuid, long companyId,
2460                    OrderByComparator orderByComparator) throws SystemException {
2461                    List<MBMessage> list = findByUuid_C(uuid, companyId, 0, 1,
2462                                    orderByComparator);
2463    
2464                    if (!list.isEmpty()) {
2465                            return list.get(0);
2466                    }
2467    
2468                    return null;
2469            }
2470    
2471            /**
2472             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
2473             *
2474             * @param uuid the uuid
2475             * @param companyId the company ID
2476             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2477             * @return the last matching message-boards message
2478             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2479             * @throws SystemException if a system exception occurred
2480             */
2481            public MBMessage findByUuid_C_Last(String uuid, long companyId,
2482                    OrderByComparator orderByComparator)
2483                    throws NoSuchMessageException, SystemException {
2484                    MBMessage mbMessage = fetchByUuid_C_Last(uuid, companyId,
2485                                    orderByComparator);
2486    
2487                    if (mbMessage != null) {
2488                            return mbMessage;
2489                    }
2490    
2491                    StringBundler msg = new StringBundler(6);
2492    
2493                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2494    
2495                    msg.append("uuid=");
2496                    msg.append(uuid);
2497    
2498                    msg.append(", companyId=");
2499                    msg.append(companyId);
2500    
2501                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2502    
2503                    throw new NoSuchMessageException(msg.toString());
2504            }
2505    
2506            /**
2507             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
2508             *
2509             * @param uuid the uuid
2510             * @param companyId the company ID
2511             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2512             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2513             * @throws SystemException if a system exception occurred
2514             */
2515            public MBMessage fetchByUuid_C_Last(String uuid, long companyId,
2516                    OrderByComparator orderByComparator) throws SystemException {
2517                    int count = countByUuid_C(uuid, companyId);
2518    
2519                    List<MBMessage> list = findByUuid_C(uuid, companyId, count - 1, count,
2520                                    orderByComparator);
2521    
2522                    if (!list.isEmpty()) {
2523                            return list.get(0);
2524                    }
2525    
2526                    return null;
2527            }
2528    
2529            /**
2530             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
2531             *
2532             * @param messageId the primary key of the current message-boards message
2533             * @param uuid the uuid
2534             * @param companyId the company ID
2535             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2536             * @return the previous, current, and next message-boards message
2537             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2538             * @throws SystemException if a system exception occurred
2539             */
2540            public MBMessage[] findByUuid_C_PrevAndNext(long messageId, String uuid,
2541                    long companyId, OrderByComparator orderByComparator)
2542                    throws NoSuchMessageException, SystemException {
2543                    MBMessage mbMessage = findByPrimaryKey(messageId);
2544    
2545                    Session session = null;
2546    
2547                    try {
2548                            session = openSession();
2549    
2550                            MBMessage[] array = new MBMessageImpl[3];
2551    
2552                            array[0] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
2553                                            companyId, orderByComparator, true);
2554    
2555                            array[1] = mbMessage;
2556    
2557                            array[2] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
2558                                            companyId, orderByComparator, false);
2559    
2560                            return array;
2561                    }
2562                    catch (Exception e) {
2563                            throw processException(e);
2564                    }
2565                    finally {
2566                            closeSession(session);
2567                    }
2568            }
2569    
2570            protected MBMessage getByUuid_C_PrevAndNext(Session session,
2571                    MBMessage mbMessage, String uuid, long companyId,
2572                    OrderByComparator orderByComparator, boolean previous) {
2573                    StringBundler query = null;
2574    
2575                    if (orderByComparator != null) {
2576                            query = new StringBundler(6 +
2577                                            (orderByComparator.getOrderByFields().length * 6));
2578                    }
2579                    else {
2580                            query = new StringBundler(3);
2581                    }
2582    
2583                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2584    
2585                    if (uuid == null) {
2586                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
2587                    }
2588                    else {
2589                            if (uuid.equals(StringPool.BLANK)) {
2590                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
2591                            }
2592                            else {
2593                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
2594                            }
2595                    }
2596    
2597                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
2598    
2599                    if (orderByComparator != null) {
2600                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2601    
2602                            if (orderByConditionFields.length > 0) {
2603                                    query.append(WHERE_AND);
2604                            }
2605    
2606                            for (int i = 0; i < orderByConditionFields.length; i++) {
2607                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2608                                    query.append(orderByConditionFields[i]);
2609    
2610                                    if ((i + 1) < orderByConditionFields.length) {
2611                                            if (orderByComparator.isAscending() ^ previous) {
2612                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2613                                            }
2614                                            else {
2615                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2616                                            }
2617                                    }
2618                                    else {
2619                                            if (orderByComparator.isAscending() ^ previous) {
2620                                                    query.append(WHERE_GREATER_THAN);
2621                                            }
2622                                            else {
2623                                                    query.append(WHERE_LESSER_THAN);
2624                                            }
2625                                    }
2626                            }
2627    
2628                            query.append(ORDER_BY_CLAUSE);
2629    
2630                            String[] orderByFields = orderByComparator.getOrderByFields();
2631    
2632                            for (int i = 0; i < orderByFields.length; i++) {
2633                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2634                                    query.append(orderByFields[i]);
2635    
2636                                    if ((i + 1) < orderByFields.length) {
2637                                            if (orderByComparator.isAscending() ^ previous) {
2638                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2639                                            }
2640                                            else {
2641                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2642                                            }
2643                                    }
2644                                    else {
2645                                            if (orderByComparator.isAscending() ^ previous) {
2646                                                    query.append(ORDER_BY_ASC);
2647                                            }
2648                                            else {
2649                                                    query.append(ORDER_BY_DESC);
2650                                            }
2651                                    }
2652                            }
2653                    }
2654    
2655                    else {
2656                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2657                    }
2658    
2659                    String sql = query.toString();
2660    
2661                    Query q = session.createQuery(sql);
2662    
2663                    q.setFirstResult(0);
2664                    q.setMaxResults(2);
2665    
2666                    QueryPos qPos = QueryPos.getInstance(q);
2667    
2668                    if (uuid != null) {
2669                            qPos.add(uuid);
2670                    }
2671    
2672                    qPos.add(companyId);
2673    
2674                    if (orderByComparator != null) {
2675                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2676    
2677                            for (Object value : values) {
2678                                    qPos.add(value);
2679                            }
2680                    }
2681    
2682                    List<MBMessage> list = q.list();
2683    
2684                    if (list.size() == 2) {
2685                            return list.get(1);
2686                    }
2687                    else {
2688                            return null;
2689                    }
2690            }
2691    
2692            /**
2693             * Returns all the message-boards messages where groupId = &#63;.
2694             *
2695             * @param groupId the group ID
2696             * @return the matching message-boards messages
2697             * @throws SystemException if a system exception occurred
2698             */
2699            public List<MBMessage> findByGroupId(long groupId)
2700                    throws SystemException {
2701                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2702            }
2703    
2704            /**
2705             * Returns a range of all the message-boards messages where groupId = &#63;.
2706             *
2707             * <p>
2708             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2709             * </p>
2710             *
2711             * @param groupId the group ID
2712             * @param start the lower bound of the range of message-boards messages
2713             * @param end the upper bound of the range of message-boards messages (not inclusive)
2714             * @return the range of matching message-boards messages
2715             * @throws SystemException if a system exception occurred
2716             */
2717            public List<MBMessage> findByGroupId(long groupId, int start, int end)
2718                    throws SystemException {
2719                    return findByGroupId(groupId, start, end, null);
2720            }
2721    
2722            /**
2723             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
2724             *
2725             * <p>
2726             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2727             * </p>
2728             *
2729             * @param groupId the group ID
2730             * @param start the lower bound of the range of message-boards messages
2731             * @param end the upper bound of the range of message-boards messages (not inclusive)
2732             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2733             * @return the ordered range of matching message-boards messages
2734             * @throws SystemException if a system exception occurred
2735             */
2736            public List<MBMessage> findByGroupId(long groupId, int start, int end,
2737                    OrderByComparator orderByComparator) throws SystemException {
2738                    FinderPath finderPath = null;
2739                    Object[] finderArgs = null;
2740    
2741                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2742                                    (orderByComparator == null)) {
2743                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
2744                            finderArgs = new Object[] { groupId };
2745                    }
2746                    else {
2747                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
2748                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
2749                    }
2750    
2751                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2752                                    finderArgs, this);
2753    
2754                    if ((list != null) && !list.isEmpty()) {
2755                            for (MBMessage mbMessage : list) {
2756                                    if ((groupId != mbMessage.getGroupId())) {
2757                                            list = null;
2758    
2759                                            break;
2760                                    }
2761                            }
2762                    }
2763    
2764                    if (list == null) {
2765                            StringBundler query = null;
2766    
2767                            if (orderByComparator != null) {
2768                                    query = new StringBundler(3 +
2769                                                    (orderByComparator.getOrderByFields().length * 3));
2770                            }
2771                            else {
2772                                    query = new StringBundler(3);
2773                            }
2774    
2775                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2776    
2777                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2778    
2779                            if (orderByComparator != null) {
2780                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2781                                            orderByComparator);
2782                            }
2783    
2784                            else {
2785                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2786                            }
2787    
2788                            String sql = query.toString();
2789    
2790                            Session session = null;
2791    
2792                            try {
2793                                    session = openSession();
2794    
2795                                    Query q = session.createQuery(sql);
2796    
2797                                    QueryPos qPos = QueryPos.getInstance(q);
2798    
2799                                    qPos.add(groupId);
2800    
2801                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2802                                                    end);
2803                            }
2804                            catch (Exception e) {
2805                                    throw processException(e);
2806                            }
2807                            finally {
2808                                    if (list == null) {
2809                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2810                                    }
2811                                    else {
2812                                            cacheResult(list);
2813    
2814                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2815                                    }
2816    
2817                                    closeSession(session);
2818                            }
2819                    }
2820    
2821                    return list;
2822            }
2823    
2824            /**
2825             * Returns the first message-boards message in the ordered set where groupId = &#63;.
2826             *
2827             * @param groupId the group ID
2828             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2829             * @return the first matching message-boards message
2830             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2831             * @throws SystemException if a system exception occurred
2832             */
2833            public MBMessage findByGroupId_First(long groupId,
2834                    OrderByComparator orderByComparator)
2835                    throws NoSuchMessageException, SystemException {
2836                    MBMessage mbMessage = fetchByGroupId_First(groupId, orderByComparator);
2837    
2838                    if (mbMessage != null) {
2839                            return mbMessage;
2840                    }
2841    
2842                    StringBundler msg = new StringBundler(4);
2843    
2844                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2845    
2846                    msg.append("groupId=");
2847                    msg.append(groupId);
2848    
2849                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2850    
2851                    throw new NoSuchMessageException(msg.toString());
2852            }
2853    
2854            /**
2855             * Returns the first message-boards message in the ordered set where groupId = &#63;.
2856             *
2857             * @param groupId the group ID
2858             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2859             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2860             * @throws SystemException if a system exception occurred
2861             */
2862            public MBMessage fetchByGroupId_First(long groupId,
2863                    OrderByComparator orderByComparator) throws SystemException {
2864                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
2865    
2866                    if (!list.isEmpty()) {
2867                            return list.get(0);
2868                    }
2869    
2870                    return null;
2871            }
2872    
2873            /**
2874             * Returns the last message-boards message in the ordered set where groupId = &#63;.
2875             *
2876             * @param groupId the group ID
2877             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2878             * @return the last matching message-boards message
2879             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2880             * @throws SystemException if a system exception occurred
2881             */
2882            public MBMessage findByGroupId_Last(long groupId,
2883                    OrderByComparator orderByComparator)
2884                    throws NoSuchMessageException, SystemException {
2885                    MBMessage mbMessage = fetchByGroupId_Last(groupId, orderByComparator);
2886    
2887                    if (mbMessage != null) {
2888                            return mbMessage;
2889                    }
2890    
2891                    StringBundler msg = new StringBundler(4);
2892    
2893                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2894    
2895                    msg.append("groupId=");
2896                    msg.append(groupId);
2897    
2898                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2899    
2900                    throw new NoSuchMessageException(msg.toString());
2901            }
2902    
2903            /**
2904             * Returns the last message-boards message in the ordered set where groupId = &#63;.
2905             *
2906             * @param groupId the group ID
2907             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2908             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2909             * @throws SystemException if a system exception occurred
2910             */
2911            public MBMessage fetchByGroupId_Last(long groupId,
2912                    OrderByComparator orderByComparator) throws SystemException {
2913                    int count = countByGroupId(groupId);
2914    
2915                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
2916                                    orderByComparator);
2917    
2918                    if (!list.isEmpty()) {
2919                            return list.get(0);
2920                    }
2921    
2922                    return null;
2923            }
2924    
2925            /**
2926             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
2927             *
2928             * @param messageId the primary key of the current message-boards message
2929             * @param groupId the group ID
2930             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2931             * @return the previous, current, and next message-boards message
2932             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2933             * @throws SystemException if a system exception occurred
2934             */
2935            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
2936                    OrderByComparator orderByComparator)
2937                    throws NoSuchMessageException, SystemException {
2938                    MBMessage mbMessage = findByPrimaryKey(messageId);
2939    
2940                    Session session = null;
2941    
2942                    try {
2943                            session = openSession();
2944    
2945                            MBMessage[] array = new MBMessageImpl[3];
2946    
2947                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
2948                                            orderByComparator, true);
2949    
2950                            array[1] = mbMessage;
2951    
2952                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
2953                                            orderByComparator, false);
2954    
2955                            return array;
2956                    }
2957                    catch (Exception e) {
2958                            throw processException(e);
2959                    }
2960                    finally {
2961                            closeSession(session);
2962                    }
2963            }
2964    
2965            protected MBMessage getByGroupId_PrevAndNext(Session session,
2966                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
2967                    boolean previous) {
2968                    StringBundler query = null;
2969    
2970                    if (orderByComparator != null) {
2971                            query = new StringBundler(6 +
2972                                            (orderByComparator.getOrderByFields().length * 6));
2973                    }
2974                    else {
2975                            query = new StringBundler(3);
2976                    }
2977    
2978                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2979    
2980                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2981    
2982                    if (orderByComparator != null) {
2983                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2984    
2985                            if (orderByConditionFields.length > 0) {
2986                                    query.append(WHERE_AND);
2987                            }
2988    
2989                            for (int i = 0; i < orderByConditionFields.length; i++) {
2990                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2991                                    query.append(orderByConditionFields[i]);
2992    
2993                                    if ((i + 1) < orderByConditionFields.length) {
2994                                            if (orderByComparator.isAscending() ^ previous) {
2995                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2996                                            }
2997                                            else {
2998                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2999                                            }
3000                                    }
3001                                    else {
3002                                            if (orderByComparator.isAscending() ^ previous) {
3003                                                    query.append(WHERE_GREATER_THAN);
3004                                            }
3005                                            else {
3006                                                    query.append(WHERE_LESSER_THAN);
3007                                            }
3008                                    }
3009                            }
3010    
3011                            query.append(ORDER_BY_CLAUSE);
3012    
3013                            String[] orderByFields = orderByComparator.getOrderByFields();
3014    
3015                            for (int i = 0; i < orderByFields.length; i++) {
3016                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3017                                    query.append(orderByFields[i]);
3018    
3019                                    if ((i + 1) < orderByFields.length) {
3020                                            if (orderByComparator.isAscending() ^ previous) {
3021                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3022                                            }
3023                                            else {
3024                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3025                                            }
3026                                    }
3027                                    else {
3028                                            if (orderByComparator.isAscending() ^ previous) {
3029                                                    query.append(ORDER_BY_ASC);
3030                                            }
3031                                            else {
3032                                                    query.append(ORDER_BY_DESC);
3033                                            }
3034                                    }
3035                            }
3036                    }
3037    
3038                    else {
3039                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3040                    }
3041    
3042                    String sql = query.toString();
3043    
3044                    Query q = session.createQuery(sql);
3045    
3046                    q.setFirstResult(0);
3047                    q.setMaxResults(2);
3048    
3049                    QueryPos qPos = QueryPos.getInstance(q);
3050    
3051                    qPos.add(groupId);
3052    
3053                    if (orderByComparator != null) {
3054                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3055    
3056                            for (Object value : values) {
3057                                    qPos.add(value);
3058                            }
3059                    }
3060    
3061                    List<MBMessage> list = q.list();
3062    
3063                    if (list.size() == 2) {
3064                            return list.get(1);
3065                    }
3066                    else {
3067                            return null;
3068                    }
3069            }
3070    
3071            /**
3072             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
3073             *
3074             * @param groupId the group ID
3075             * @return the matching message-boards messages that the user has permission to view
3076             * @throws SystemException if a system exception occurred
3077             */
3078            public List<MBMessage> filterFindByGroupId(long groupId)
3079                    throws SystemException {
3080                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
3081                            QueryUtil.ALL_POS, null);
3082            }
3083    
3084            /**
3085             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
3086             *
3087             * <p>
3088             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3089             * </p>
3090             *
3091             * @param groupId the group ID
3092             * @param start the lower bound of the range of message-boards messages
3093             * @param end the upper bound of the range of message-boards messages (not inclusive)
3094             * @return the range of matching message-boards messages that the user has permission to view
3095             * @throws SystemException if a system exception occurred
3096             */
3097            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end)
3098                    throws SystemException {
3099                    return filterFindByGroupId(groupId, start, end, null);
3100            }
3101    
3102            /**
3103             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
3104             *
3105             * <p>
3106             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3107             * </p>
3108             *
3109             * @param groupId the group ID
3110             * @param start the lower bound of the range of message-boards messages
3111             * @param end the upper bound of the range of message-boards messages (not inclusive)
3112             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3113             * @return the ordered range of matching message-boards messages that the user has permission to view
3114             * @throws SystemException if a system exception occurred
3115             */
3116            public List<MBMessage> filterFindByGroupId(long groupId, int start,
3117                    int end, OrderByComparator orderByComparator) throws SystemException {
3118                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3119                            return findByGroupId(groupId, start, end, orderByComparator);
3120                    }
3121    
3122                    StringBundler query = null;
3123    
3124                    if (orderByComparator != null) {
3125                            query = new StringBundler(3 +
3126                                            (orderByComparator.getOrderByFields().length * 3));
3127                    }
3128                    else {
3129                            query = new StringBundler(3);
3130                    }
3131    
3132                    if (getDB().isSupportsInlineDistinct()) {
3133                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
3134                    }
3135                    else {
3136                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
3137                    }
3138    
3139                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3140    
3141                    if (!getDB().isSupportsInlineDistinct()) {
3142                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
3143                    }
3144    
3145                    if (orderByComparator != null) {
3146                            if (getDB().isSupportsInlineDistinct()) {
3147                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3148                                            orderByComparator);
3149                            }
3150                            else {
3151                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3152                                            orderByComparator);
3153                            }
3154                    }
3155    
3156                    else {
3157                            if (getDB().isSupportsInlineDistinct()) {
3158                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3159                            }
3160                            else {
3161                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
3162                            }
3163                    }
3164    
3165                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3166                                    MBMessage.class.getName(),
3167                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3168    
3169                    Session session = null;
3170    
3171                    try {
3172                            session = openSession();
3173    
3174                            SQLQuery q = session.createSQLQuery(sql);
3175    
3176                            if (getDB().isSupportsInlineDistinct()) {
3177                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
3178                            }
3179                            else {
3180                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
3181                            }
3182    
3183                            QueryPos qPos = QueryPos.getInstance(q);
3184    
3185                            qPos.add(groupId);
3186    
3187                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
3188                    }
3189                    catch (Exception e) {
3190                            throw processException(e);
3191                    }
3192                    finally {
3193                            closeSession(session);
3194                    }
3195            }
3196    
3197            /**
3198             * 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;.
3199             *
3200             * @param messageId the primary key of the current message-boards message
3201             * @param groupId the group ID
3202             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3203             * @return the previous, current, and next message-boards message
3204             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3205             * @throws SystemException if a system exception occurred
3206             */
3207            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
3208                    long groupId, OrderByComparator orderByComparator)
3209                    throws NoSuchMessageException, SystemException {
3210                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3211                            return findByGroupId_PrevAndNext(messageId, groupId,
3212                                    orderByComparator);
3213                    }
3214    
3215                    MBMessage mbMessage = findByPrimaryKey(messageId);
3216    
3217                    Session session = null;
3218    
3219                    try {
3220                            session = openSession();
3221    
3222                            MBMessage[] array = new MBMessageImpl[3];
3223    
3224                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
3225                                            groupId, orderByComparator, true);
3226    
3227                            array[1] = mbMessage;
3228    
3229                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
3230                                            groupId, orderByComparator, false);
3231    
3232                            return array;
3233                    }
3234                    catch (Exception e) {
3235                            throw processException(e);
3236                    }
3237                    finally {
3238                            closeSession(session);
3239                    }
3240            }
3241    
3242            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
3243                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
3244                    boolean previous) {
3245                    StringBundler query = null;
3246    
3247                    if (orderByComparator != null) {
3248                            query = new StringBundler(6 +
3249                                            (orderByComparator.getOrderByFields().length * 6));
3250                    }
3251                    else {
3252                            query = new StringBundler(3);
3253                    }
3254    
3255                    if (getDB().isSupportsInlineDistinct()) {
3256                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
3257                    }
3258                    else {
3259                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
3260                    }
3261    
3262                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3263    
3264                    if (!getDB().isSupportsInlineDistinct()) {
3265                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
3266                    }
3267    
3268                    if (orderByComparator != null) {
3269                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3270    
3271                            if (orderByConditionFields.length > 0) {
3272                                    query.append(WHERE_AND);
3273                            }
3274    
3275                            for (int i = 0; i < orderByConditionFields.length; i++) {
3276                                    if (getDB().isSupportsInlineDistinct()) {
3277                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3278                                    }
3279                                    else {
3280                                            query.append(_ORDER_BY_ENTITY_TABLE);
3281                                    }
3282    
3283                                    query.append(orderByConditionFields[i]);
3284    
3285                                    if ((i + 1) < orderByConditionFields.length) {
3286                                            if (orderByComparator.isAscending() ^ previous) {
3287                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3288                                            }
3289                                            else {
3290                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3291                                            }
3292                                    }
3293                                    else {
3294                                            if (orderByComparator.isAscending() ^ previous) {
3295                                                    query.append(WHERE_GREATER_THAN);
3296                                            }
3297                                            else {
3298                                                    query.append(WHERE_LESSER_THAN);
3299                                            }
3300                                    }
3301                            }
3302    
3303                            query.append(ORDER_BY_CLAUSE);
3304    
3305                            String[] orderByFields = orderByComparator.getOrderByFields();
3306    
3307                            for (int i = 0; i < orderByFields.length; i++) {
3308                                    if (getDB().isSupportsInlineDistinct()) {
3309                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3310                                    }
3311                                    else {
3312                                            query.append(_ORDER_BY_ENTITY_TABLE);
3313                                    }
3314    
3315                                    query.append(orderByFields[i]);
3316    
3317                                    if ((i + 1) < orderByFields.length) {
3318                                            if (orderByComparator.isAscending() ^ previous) {
3319                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3320                                            }
3321                                            else {
3322                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3323                                            }
3324                                    }
3325                                    else {
3326                                            if (orderByComparator.isAscending() ^ previous) {
3327                                                    query.append(ORDER_BY_ASC);
3328                                            }
3329                                            else {
3330                                                    query.append(ORDER_BY_DESC);
3331                                            }
3332                                    }
3333                            }
3334                    }
3335    
3336                    else {
3337                            if (getDB().isSupportsInlineDistinct()) {
3338                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3339                            }
3340                            else {
3341                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
3342                            }
3343                    }
3344    
3345                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3346                                    MBMessage.class.getName(),
3347                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3348    
3349                    SQLQuery q = session.createSQLQuery(sql);
3350    
3351                    q.setFirstResult(0);
3352                    q.setMaxResults(2);
3353    
3354                    if (getDB().isSupportsInlineDistinct()) {
3355                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
3356                    }
3357                    else {
3358                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
3359                    }
3360    
3361                    QueryPos qPos = QueryPos.getInstance(q);
3362    
3363                    qPos.add(groupId);
3364    
3365                    if (orderByComparator != null) {
3366                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3367    
3368                            for (Object value : values) {
3369                                    qPos.add(value);
3370                            }
3371                    }
3372    
3373                    List<MBMessage> list = q.list();
3374    
3375                    if (list.size() == 2) {
3376                            return list.get(1);
3377                    }
3378                    else {
3379                            return null;
3380                    }
3381            }
3382    
3383            /**
3384             * Returns all the message-boards messages where companyId = &#63;.
3385             *
3386             * @param companyId the company ID
3387             * @return the matching message-boards messages
3388             * @throws SystemException if a system exception occurred
3389             */
3390            public List<MBMessage> findByCompanyId(long companyId)
3391                    throws SystemException {
3392                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3393                            null);
3394            }
3395    
3396            /**
3397             * Returns a range of all the message-boards messages where companyId = &#63;.
3398             *
3399             * <p>
3400             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3401             * </p>
3402             *
3403             * @param companyId the company ID
3404             * @param start the lower bound of the range of message-boards messages
3405             * @param end the upper bound of the range of message-boards messages (not inclusive)
3406             * @return the range of matching message-boards messages
3407             * @throws SystemException if a system exception occurred
3408             */
3409            public List<MBMessage> findByCompanyId(long companyId, int start, int end)
3410                    throws SystemException {
3411                    return findByCompanyId(companyId, start, end, null);
3412            }
3413    
3414            /**
3415             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
3416             *
3417             * <p>
3418             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3419             * </p>
3420             *
3421             * @param companyId the company ID
3422             * @param start the lower bound of the range of message-boards messages
3423             * @param end the upper bound of the range of message-boards messages (not inclusive)
3424             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3425             * @return the ordered range of matching message-boards messages
3426             * @throws SystemException if a system exception occurred
3427             */
3428            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
3429                    OrderByComparator orderByComparator) throws SystemException {
3430                    FinderPath finderPath = null;
3431                    Object[] finderArgs = null;
3432    
3433                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3434                                    (orderByComparator == null)) {
3435                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
3436                            finderArgs = new Object[] { companyId };
3437                    }
3438                    else {
3439                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
3440                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
3441                    }
3442    
3443                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3444                                    finderArgs, this);
3445    
3446                    if ((list != null) && !list.isEmpty()) {
3447                            for (MBMessage mbMessage : list) {
3448                                    if ((companyId != mbMessage.getCompanyId())) {
3449                                            list = null;
3450    
3451                                            break;
3452                                    }
3453                            }
3454                    }
3455    
3456                    if (list == null) {
3457                            StringBundler query = null;
3458    
3459                            if (orderByComparator != null) {
3460                                    query = new StringBundler(3 +
3461                                                    (orderByComparator.getOrderByFields().length * 3));
3462                            }
3463                            else {
3464                                    query = new StringBundler(3);
3465                            }
3466    
3467                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3468    
3469                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3470    
3471                            if (orderByComparator != null) {
3472                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3473                                            orderByComparator);
3474                            }
3475    
3476                            else {
3477                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3478                            }
3479    
3480                            String sql = query.toString();
3481    
3482                            Session session = null;
3483    
3484                            try {
3485                                    session = openSession();
3486    
3487                                    Query q = session.createQuery(sql);
3488    
3489                                    QueryPos qPos = QueryPos.getInstance(q);
3490    
3491                                    qPos.add(companyId);
3492    
3493                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3494                                                    end);
3495                            }
3496                            catch (Exception e) {
3497                                    throw processException(e);
3498                            }
3499                            finally {
3500                                    if (list == null) {
3501                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3502                                    }
3503                                    else {
3504                                            cacheResult(list);
3505    
3506                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3507                                    }
3508    
3509                                    closeSession(session);
3510                            }
3511                    }
3512    
3513                    return list;
3514            }
3515    
3516            /**
3517             * Returns the first message-boards message in the ordered set where companyId = &#63;.
3518             *
3519             * @param companyId the company ID
3520             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3521             * @return the first matching message-boards message
3522             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3523             * @throws SystemException if a system exception occurred
3524             */
3525            public MBMessage findByCompanyId_First(long companyId,
3526                    OrderByComparator orderByComparator)
3527                    throws NoSuchMessageException, SystemException {
3528                    MBMessage mbMessage = fetchByCompanyId_First(companyId,
3529                                    orderByComparator);
3530    
3531                    if (mbMessage != null) {
3532                            return mbMessage;
3533                    }
3534    
3535                    StringBundler msg = new StringBundler(4);
3536    
3537                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3538    
3539                    msg.append("companyId=");
3540                    msg.append(companyId);
3541    
3542                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3543    
3544                    throw new NoSuchMessageException(msg.toString());
3545            }
3546    
3547            /**
3548             * Returns the first message-boards message in the ordered set where companyId = &#63;.
3549             *
3550             * @param companyId the company ID
3551             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3552             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3553             * @throws SystemException if a system exception occurred
3554             */
3555            public MBMessage fetchByCompanyId_First(long companyId,
3556                    OrderByComparator orderByComparator) throws SystemException {
3557                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
3558                                    orderByComparator);
3559    
3560                    if (!list.isEmpty()) {
3561                            return list.get(0);
3562                    }
3563    
3564                    return null;
3565            }
3566    
3567            /**
3568             * Returns the last message-boards message in the ordered set where companyId = &#63;.
3569             *
3570             * @param companyId the company ID
3571             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3572             * @return the last matching message-boards message
3573             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3574             * @throws SystemException if a system exception occurred
3575             */
3576            public MBMessage findByCompanyId_Last(long companyId,
3577                    OrderByComparator orderByComparator)
3578                    throws NoSuchMessageException, SystemException {
3579                    MBMessage mbMessage = fetchByCompanyId_Last(companyId, orderByComparator);
3580    
3581                    if (mbMessage != null) {
3582                            return mbMessage;
3583                    }
3584    
3585                    StringBundler msg = new StringBundler(4);
3586    
3587                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3588    
3589                    msg.append("companyId=");
3590                    msg.append(companyId);
3591    
3592                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3593    
3594                    throw new NoSuchMessageException(msg.toString());
3595            }
3596    
3597            /**
3598             * Returns the last message-boards message in the ordered set where companyId = &#63;.
3599             *
3600             * @param companyId the company ID
3601             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3602             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3603             * @throws SystemException if a system exception occurred
3604             */
3605            public MBMessage fetchByCompanyId_Last(long companyId,
3606                    OrderByComparator orderByComparator) throws SystemException {
3607                    int count = countByCompanyId(companyId);
3608    
3609                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
3610                                    orderByComparator);
3611    
3612                    if (!list.isEmpty()) {
3613                            return list.get(0);
3614                    }
3615    
3616                    return null;
3617            }
3618    
3619            /**
3620             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
3621             *
3622             * @param messageId the primary key of the current message-boards message
3623             * @param companyId the company ID
3624             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3625             * @return the previous, current, and next message-boards message
3626             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3627             * @throws SystemException if a system exception occurred
3628             */
3629            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
3630                    long companyId, OrderByComparator orderByComparator)
3631                    throws NoSuchMessageException, SystemException {
3632                    MBMessage mbMessage = findByPrimaryKey(messageId);
3633    
3634                    Session session = null;
3635    
3636                    try {
3637                            session = openSession();
3638    
3639                            MBMessage[] array = new MBMessageImpl[3];
3640    
3641                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
3642                                            companyId, orderByComparator, true);
3643    
3644                            array[1] = mbMessage;
3645    
3646                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
3647                                            companyId, orderByComparator, false);
3648    
3649                            return array;
3650                    }
3651                    catch (Exception e) {
3652                            throw processException(e);
3653                    }
3654                    finally {
3655                            closeSession(session);
3656                    }
3657            }
3658    
3659            protected MBMessage getByCompanyId_PrevAndNext(Session session,
3660                    MBMessage mbMessage, long companyId,
3661                    OrderByComparator orderByComparator, boolean previous) {
3662                    StringBundler query = null;
3663    
3664                    if (orderByComparator != null) {
3665                            query = new StringBundler(6 +
3666                                            (orderByComparator.getOrderByFields().length * 6));
3667                    }
3668                    else {
3669                            query = new StringBundler(3);
3670                    }
3671    
3672                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3673    
3674                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3675    
3676                    if (orderByComparator != null) {
3677                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3678    
3679                            if (orderByConditionFields.length > 0) {
3680                                    query.append(WHERE_AND);
3681                            }
3682    
3683                            for (int i = 0; i < orderByConditionFields.length; i++) {
3684                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3685                                    query.append(orderByConditionFields[i]);
3686    
3687                                    if ((i + 1) < orderByConditionFields.length) {
3688                                            if (orderByComparator.isAscending() ^ previous) {
3689                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3690                                            }
3691                                            else {
3692                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3693                                            }
3694                                    }
3695                                    else {
3696                                            if (orderByComparator.isAscending() ^ previous) {
3697                                                    query.append(WHERE_GREATER_THAN);
3698                                            }
3699                                            else {
3700                                                    query.append(WHERE_LESSER_THAN);
3701                                            }
3702                                    }
3703                            }
3704    
3705                            query.append(ORDER_BY_CLAUSE);
3706    
3707                            String[] orderByFields = orderByComparator.getOrderByFields();
3708    
3709                            for (int i = 0; i < orderByFields.length; i++) {
3710                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3711                                    query.append(orderByFields[i]);
3712    
3713                                    if ((i + 1) < orderByFields.length) {
3714                                            if (orderByComparator.isAscending() ^ previous) {
3715                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3716                                            }
3717                                            else {
3718                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3719                                            }
3720                                    }
3721                                    else {
3722                                            if (orderByComparator.isAscending() ^ previous) {
3723                                                    query.append(ORDER_BY_ASC);
3724                                            }
3725                                            else {
3726                                                    query.append(ORDER_BY_DESC);
3727                                            }
3728                                    }
3729                            }
3730                    }
3731    
3732                    else {
3733                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3734                    }
3735    
3736                    String sql = query.toString();
3737    
3738                    Query q = session.createQuery(sql);
3739    
3740                    q.setFirstResult(0);
3741                    q.setMaxResults(2);
3742    
3743                    QueryPos qPos = QueryPos.getInstance(q);
3744    
3745                    qPos.add(companyId);
3746    
3747                    if (orderByComparator != null) {
3748                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3749    
3750                            for (Object value : values) {
3751                                    qPos.add(value);
3752                            }
3753                    }
3754    
3755                    List<MBMessage> list = q.list();
3756    
3757                    if (list.size() == 2) {
3758                            return list.get(1);
3759                    }
3760                    else {
3761                            return null;
3762                    }
3763            }
3764    
3765            /**
3766             * Returns all the message-boards messages where threadId = &#63;.
3767             *
3768             * @param threadId the thread ID
3769             * @return the matching message-boards messages
3770             * @throws SystemException if a system exception occurred
3771             */
3772            public List<MBMessage> findByThreadId(long threadId)
3773                    throws SystemException {
3774                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3775                            null);
3776            }
3777    
3778            /**
3779             * Returns a range of all the message-boards messages where threadId = &#63;.
3780             *
3781             * <p>
3782             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3783             * </p>
3784             *
3785             * @param threadId the thread ID
3786             * @param start the lower bound of the range of message-boards messages
3787             * @param end the upper bound of the range of message-boards messages (not inclusive)
3788             * @return the range of matching message-boards messages
3789             * @throws SystemException if a system exception occurred
3790             */
3791            public List<MBMessage> findByThreadId(long threadId, int start, int end)
3792                    throws SystemException {
3793                    return findByThreadId(threadId, start, end, null);
3794            }
3795    
3796            /**
3797             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3798             *
3799             * <p>
3800             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3801             * </p>
3802             *
3803             * @param threadId the thread ID
3804             * @param start the lower bound of the range of message-boards messages
3805             * @param end the upper bound of the range of message-boards messages (not inclusive)
3806             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3807             * @return the ordered range of matching message-boards messages
3808             * @throws SystemException if a system exception occurred
3809             */
3810            public List<MBMessage> findByThreadId(long threadId, int start, int end,
3811                    OrderByComparator orderByComparator) throws SystemException {
3812                    FinderPath finderPath = null;
3813                    Object[] finderArgs = null;
3814    
3815                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3816                                    (orderByComparator == null)) {
3817                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
3818                            finderArgs = new Object[] { threadId };
3819                    }
3820                    else {
3821                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
3822                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3823                    }
3824    
3825                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3826                                    finderArgs, this);
3827    
3828                    if ((list != null) && !list.isEmpty()) {
3829                            for (MBMessage mbMessage : list) {
3830                                    if ((threadId != mbMessage.getThreadId())) {
3831                                            list = null;
3832    
3833                                            break;
3834                                    }
3835                            }
3836                    }
3837    
3838                    if (list == null) {
3839                            StringBundler query = null;
3840    
3841                            if (orderByComparator != null) {
3842                                    query = new StringBundler(3 +
3843                                                    (orderByComparator.getOrderByFields().length * 3));
3844                            }
3845                            else {
3846                                    query = new StringBundler(3);
3847                            }
3848    
3849                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3850    
3851                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3852    
3853                            if (orderByComparator != null) {
3854                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3855                                            orderByComparator);
3856                            }
3857    
3858                            else {
3859                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3860                            }
3861    
3862                            String sql = query.toString();
3863    
3864                            Session session = null;
3865    
3866                            try {
3867                                    session = openSession();
3868    
3869                                    Query q = session.createQuery(sql);
3870    
3871                                    QueryPos qPos = QueryPos.getInstance(q);
3872    
3873                                    qPos.add(threadId);
3874    
3875                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3876                                                    end);
3877                            }
3878                            catch (Exception e) {
3879                                    throw processException(e);
3880                            }
3881                            finally {
3882                                    if (list == null) {
3883                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3884                                    }
3885                                    else {
3886                                            cacheResult(list);
3887    
3888                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3889                                    }
3890    
3891                                    closeSession(session);
3892                            }
3893                    }
3894    
3895                    return list;
3896            }
3897    
3898            /**
3899             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3900             *
3901             * @param threadId the thread ID
3902             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3903             * @return the first matching message-boards message
3904             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3905             * @throws SystemException if a system exception occurred
3906             */
3907            public MBMessage findByThreadId_First(long threadId,
3908                    OrderByComparator orderByComparator)
3909                    throws NoSuchMessageException, SystemException {
3910                    MBMessage mbMessage = fetchByThreadId_First(threadId, orderByComparator);
3911    
3912                    if (mbMessage != null) {
3913                            return mbMessage;
3914                    }
3915    
3916                    StringBundler msg = new StringBundler(4);
3917    
3918                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3919    
3920                    msg.append("threadId=");
3921                    msg.append(threadId);
3922    
3923                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3924    
3925                    throw new NoSuchMessageException(msg.toString());
3926            }
3927    
3928            /**
3929             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3930             *
3931             * @param threadId the thread ID
3932             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3933             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3934             * @throws SystemException if a system exception occurred
3935             */
3936            public MBMessage fetchByThreadId_First(long threadId,
3937                    OrderByComparator orderByComparator) throws SystemException {
3938                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
3939    
3940                    if (!list.isEmpty()) {
3941                            return list.get(0);
3942                    }
3943    
3944                    return null;
3945            }
3946    
3947            /**
3948             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3949             *
3950             * @param threadId the thread ID
3951             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3952             * @return the last matching message-boards message
3953             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3954             * @throws SystemException if a system exception occurred
3955             */
3956            public MBMessage findByThreadId_Last(long threadId,
3957                    OrderByComparator orderByComparator)
3958                    throws NoSuchMessageException, SystemException {
3959                    MBMessage mbMessage = fetchByThreadId_Last(threadId, orderByComparator);
3960    
3961                    if (mbMessage != null) {
3962                            return mbMessage;
3963                    }
3964    
3965                    StringBundler msg = new StringBundler(4);
3966    
3967                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3968    
3969                    msg.append("threadId=");
3970                    msg.append(threadId);
3971    
3972                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3973    
3974                    throw new NoSuchMessageException(msg.toString());
3975            }
3976    
3977            /**
3978             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3979             *
3980             * @param threadId the thread ID
3981             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3982             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3983             * @throws SystemException if a system exception occurred
3984             */
3985            public MBMessage fetchByThreadId_Last(long threadId,
3986                    OrderByComparator orderByComparator) throws SystemException {
3987                    int count = countByThreadId(threadId);
3988    
3989                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
3990                                    orderByComparator);
3991    
3992                    if (!list.isEmpty()) {
3993                            return list.get(0);
3994                    }
3995    
3996                    return null;
3997            }
3998    
3999            /**
4000             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
4001             *
4002             * @param messageId the primary key of the current message-boards message
4003             * @param threadId the thread ID
4004             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4005             * @return the previous, current, and next message-boards message
4006             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4007             * @throws SystemException if a system exception occurred
4008             */
4009            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
4010                    long threadId, OrderByComparator orderByComparator)
4011                    throws NoSuchMessageException, SystemException {
4012                    MBMessage mbMessage = findByPrimaryKey(messageId);
4013    
4014                    Session session = null;
4015    
4016                    try {
4017                            session = openSession();
4018    
4019                            MBMessage[] array = new MBMessageImpl[3];
4020    
4021                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
4022                                            orderByComparator, true);
4023    
4024                            array[1] = mbMessage;
4025    
4026                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
4027                                            orderByComparator, false);
4028    
4029                            return array;
4030                    }
4031                    catch (Exception e) {
4032                            throw processException(e);
4033                    }
4034                    finally {
4035                            closeSession(session);
4036                    }
4037            }
4038    
4039            protected MBMessage getByThreadId_PrevAndNext(Session session,
4040                    MBMessage mbMessage, long threadId,
4041                    OrderByComparator orderByComparator, boolean previous) {
4042                    StringBundler query = null;
4043    
4044                    if (orderByComparator != null) {
4045                            query = new StringBundler(6 +
4046                                            (orderByComparator.getOrderByFields().length * 6));
4047                    }
4048                    else {
4049                            query = new StringBundler(3);
4050                    }
4051    
4052                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4053    
4054                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
4055    
4056                    if (orderByComparator != null) {
4057                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4058    
4059                            if (orderByConditionFields.length > 0) {
4060                                    query.append(WHERE_AND);
4061                            }
4062    
4063                            for (int i = 0; i < orderByConditionFields.length; i++) {
4064                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4065                                    query.append(orderByConditionFields[i]);
4066    
4067                                    if ((i + 1) < orderByConditionFields.length) {
4068                                            if (orderByComparator.isAscending() ^ previous) {
4069                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4070                                            }
4071                                            else {
4072                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4073                                            }
4074                                    }
4075                                    else {
4076                                            if (orderByComparator.isAscending() ^ previous) {
4077                                                    query.append(WHERE_GREATER_THAN);
4078                                            }
4079                                            else {
4080                                                    query.append(WHERE_LESSER_THAN);
4081                                            }
4082                                    }
4083                            }
4084    
4085                            query.append(ORDER_BY_CLAUSE);
4086    
4087                            String[] orderByFields = orderByComparator.getOrderByFields();
4088    
4089                            for (int i = 0; i < orderByFields.length; i++) {
4090                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4091                                    query.append(orderByFields[i]);
4092    
4093                                    if ((i + 1) < orderByFields.length) {
4094                                            if (orderByComparator.isAscending() ^ previous) {
4095                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4096                                            }
4097                                            else {
4098                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4099                                            }
4100                                    }
4101                                    else {
4102                                            if (orderByComparator.isAscending() ^ previous) {
4103                                                    query.append(ORDER_BY_ASC);
4104                                            }
4105                                            else {
4106                                                    query.append(ORDER_BY_DESC);
4107                                            }
4108                                    }
4109                            }
4110                    }
4111    
4112                    else {
4113                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4114                    }
4115    
4116                    String sql = query.toString();
4117    
4118                    Query q = session.createQuery(sql);
4119    
4120                    q.setFirstResult(0);
4121                    q.setMaxResults(2);
4122    
4123                    QueryPos qPos = QueryPos.getInstance(q);
4124    
4125                    qPos.add(threadId);
4126    
4127                    if (orderByComparator != null) {
4128                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4129    
4130                            for (Object value : values) {
4131                                    qPos.add(value);
4132                            }
4133                    }
4134    
4135                    List<MBMessage> list = q.list();
4136    
4137                    if (list.size() == 2) {
4138                            return list.get(1);
4139                    }
4140                    else {
4141                            return null;
4142                    }
4143            }
4144    
4145            /**
4146             * Returns all the message-boards messages where threadId = &#63;.
4147             *
4148             * @param threadId the thread ID
4149             * @return the matching message-boards messages
4150             * @throws SystemException if a system exception occurred
4151             */
4152            public List<MBMessage> findByThreadReplies(long threadId)
4153                    throws SystemException {
4154                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
4155                            QueryUtil.ALL_POS, null);
4156            }
4157    
4158            /**
4159             * Returns a range of all the message-boards messages where threadId = &#63;.
4160             *
4161             * <p>
4162             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4163             * </p>
4164             *
4165             * @param threadId the thread ID
4166             * @param start the lower bound of the range of message-boards messages
4167             * @param end the upper bound of the range of message-boards messages (not inclusive)
4168             * @return the range of matching message-boards messages
4169             * @throws SystemException if a system exception occurred
4170             */
4171            public List<MBMessage> findByThreadReplies(long threadId, int start, int end)
4172                    throws SystemException {
4173                    return findByThreadReplies(threadId, start, end, null);
4174            }
4175    
4176            /**
4177             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
4178             *
4179             * <p>
4180             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4181             * </p>
4182             *
4183             * @param threadId the thread ID
4184             * @param start the lower bound of the range of message-boards messages
4185             * @param end the upper bound of the range of message-boards messages (not inclusive)
4186             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4187             * @return the ordered range of matching message-boards messages
4188             * @throws SystemException if a system exception occurred
4189             */
4190            public List<MBMessage> findByThreadReplies(long threadId, int start,
4191                    int end, OrderByComparator orderByComparator) throws SystemException {
4192                    FinderPath finderPath = null;
4193                    Object[] finderArgs = null;
4194    
4195                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4196                                    (orderByComparator == null)) {
4197                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
4198                            finderArgs = new Object[] { threadId };
4199                    }
4200                    else {
4201                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
4202                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
4203                    }
4204    
4205                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4206                                    finderArgs, this);
4207    
4208                    if ((list != null) && !list.isEmpty()) {
4209                            for (MBMessage mbMessage : list) {
4210                                    if ((threadId != mbMessage.getThreadId())) {
4211                                            list = null;
4212    
4213                                            break;
4214                                    }
4215                            }
4216                    }
4217    
4218                    if (list == null) {
4219                            StringBundler query = null;
4220    
4221                            if (orderByComparator != null) {
4222                                    query = new StringBundler(3 +
4223                                                    (orderByComparator.getOrderByFields().length * 3));
4224                            }
4225                            else {
4226                                    query = new StringBundler(3);
4227                            }
4228    
4229                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4230    
4231                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4232    
4233                            if (orderByComparator != null) {
4234                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4235                                            orderByComparator);
4236                            }
4237    
4238                            else {
4239                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4240                            }
4241    
4242                            String sql = query.toString();
4243    
4244                            Session session = null;
4245    
4246                            try {
4247                                    session = openSession();
4248    
4249                                    Query q = session.createQuery(sql);
4250    
4251                                    QueryPos qPos = QueryPos.getInstance(q);
4252    
4253                                    qPos.add(threadId);
4254    
4255                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
4256                                                    end);
4257                            }
4258                            catch (Exception e) {
4259                                    throw processException(e);
4260                            }
4261                            finally {
4262                                    if (list == null) {
4263                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4264                                    }
4265                                    else {
4266                                            cacheResult(list);
4267    
4268                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4269                                    }
4270    
4271                                    closeSession(session);
4272                            }
4273                    }
4274    
4275                    return list;
4276            }
4277    
4278            /**
4279             * Returns the first message-boards message in the ordered set where threadId = &#63;.
4280             *
4281             * @param threadId the thread ID
4282             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4283             * @return the first matching message-boards message
4284             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4285             * @throws SystemException if a system exception occurred
4286             */
4287            public MBMessage findByThreadReplies_First(long threadId,
4288                    OrderByComparator orderByComparator)
4289                    throws NoSuchMessageException, SystemException {
4290                    MBMessage mbMessage = fetchByThreadReplies_First(threadId,
4291                                    orderByComparator);
4292    
4293                    if (mbMessage != null) {
4294                            return mbMessage;
4295                    }
4296    
4297                    StringBundler msg = new StringBundler(4);
4298    
4299                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4300    
4301                    msg.append("threadId=");
4302                    msg.append(threadId);
4303    
4304                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4305    
4306                    throw new NoSuchMessageException(msg.toString());
4307            }
4308    
4309            /**
4310             * Returns the first message-boards message in the ordered set where threadId = &#63;.
4311             *
4312             * @param threadId the thread ID
4313             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4314             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4315             * @throws SystemException if a system exception occurred
4316             */
4317            public MBMessage fetchByThreadReplies_First(long threadId,
4318                    OrderByComparator orderByComparator) throws SystemException {
4319                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
4320                                    orderByComparator);
4321    
4322                    if (!list.isEmpty()) {
4323                            return list.get(0);
4324                    }
4325    
4326                    return null;
4327            }
4328    
4329            /**
4330             * Returns the last message-boards message in the ordered set where threadId = &#63;.
4331             *
4332             * @param threadId the thread ID
4333             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4334             * @return the last matching message-boards message
4335             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4336             * @throws SystemException if a system exception occurred
4337             */
4338            public MBMessage findByThreadReplies_Last(long threadId,
4339                    OrderByComparator orderByComparator)
4340                    throws NoSuchMessageException, SystemException {
4341                    MBMessage mbMessage = fetchByThreadReplies_Last(threadId,
4342                                    orderByComparator);
4343    
4344                    if (mbMessage != null) {
4345                            return mbMessage;
4346                    }
4347    
4348                    StringBundler msg = new StringBundler(4);
4349    
4350                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4351    
4352                    msg.append("threadId=");
4353                    msg.append(threadId);
4354    
4355                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4356    
4357                    throw new NoSuchMessageException(msg.toString());
4358            }
4359    
4360            /**
4361             * Returns the last message-boards message in the ordered set where threadId = &#63;.
4362             *
4363             * @param threadId the thread ID
4364             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4365             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4366             * @throws SystemException if a system exception occurred
4367             */
4368            public MBMessage fetchByThreadReplies_Last(long threadId,
4369                    OrderByComparator orderByComparator) throws SystemException {
4370                    int count = countByThreadReplies(threadId);
4371    
4372                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
4373                                    orderByComparator);
4374    
4375                    if (!list.isEmpty()) {
4376                            return list.get(0);
4377                    }
4378    
4379                    return null;
4380            }
4381    
4382            /**
4383             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
4384             *
4385             * @param messageId the primary key of the current message-boards message
4386             * @param threadId the thread ID
4387             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4388             * @return the previous, current, and next message-boards message
4389             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4390             * @throws SystemException if a system exception occurred
4391             */
4392            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
4393                    long threadId, OrderByComparator orderByComparator)
4394                    throws NoSuchMessageException, SystemException {
4395                    MBMessage mbMessage = findByPrimaryKey(messageId);
4396    
4397                    Session session = null;
4398    
4399                    try {
4400                            session = openSession();
4401    
4402                            MBMessage[] array = new MBMessageImpl[3];
4403    
4404                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
4405                                            threadId, orderByComparator, true);
4406    
4407                            array[1] = mbMessage;
4408    
4409                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
4410                                            threadId, orderByComparator, false);
4411    
4412                            return array;
4413                    }
4414                    catch (Exception e) {
4415                            throw processException(e);
4416                    }
4417                    finally {
4418                            closeSession(session);
4419                    }
4420            }
4421    
4422            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
4423                    MBMessage mbMessage, long threadId,
4424                    OrderByComparator orderByComparator, boolean previous) {
4425                    StringBundler query = null;
4426    
4427                    if (orderByComparator != null) {
4428                            query = new StringBundler(6 +
4429                                            (orderByComparator.getOrderByFields().length * 6));
4430                    }
4431                    else {
4432                            query = new StringBundler(3);
4433                    }
4434    
4435                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4436    
4437                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
4438    
4439                    if (orderByComparator != null) {
4440                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4441    
4442                            if (orderByConditionFields.length > 0) {
4443                                    query.append(WHERE_AND);
4444                            }
4445    
4446                            for (int i = 0; i < orderByConditionFields.length; i++) {
4447                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4448                                    query.append(orderByConditionFields[i]);
4449    
4450                                    if ((i + 1) < orderByConditionFields.length) {
4451                                            if (orderByComparator.isAscending() ^ previous) {
4452                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4453                                            }
4454                                            else {
4455                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4456                                            }
4457                                    }
4458                                    else {
4459                                            if (orderByComparator.isAscending() ^ previous) {
4460                                                    query.append(WHERE_GREATER_THAN);
4461                                            }
4462                                            else {
4463                                                    query.append(WHERE_LESSER_THAN);
4464                                            }
4465                                    }
4466                            }
4467    
4468                            query.append(ORDER_BY_CLAUSE);
4469    
4470                            String[] orderByFields = orderByComparator.getOrderByFields();
4471    
4472                            for (int i = 0; i < orderByFields.length; i++) {
4473                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4474                                    query.append(orderByFields[i]);
4475    
4476                                    if ((i + 1) < orderByFields.length) {
4477                                            if (orderByComparator.isAscending() ^ previous) {
4478                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4479                                            }
4480                                            else {
4481                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4482                                            }
4483                                    }
4484                                    else {
4485                                            if (orderByComparator.isAscending() ^ previous) {
4486                                                    query.append(ORDER_BY_ASC);
4487                                            }
4488                                            else {
4489                                                    query.append(ORDER_BY_DESC);
4490                                            }
4491                                    }
4492                            }
4493                    }
4494    
4495                    else {
4496                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4497                    }
4498    
4499                    String sql = query.toString();
4500    
4501                    Query q = session.createQuery(sql);
4502    
4503                    q.setFirstResult(0);
4504                    q.setMaxResults(2);
4505    
4506                    QueryPos qPos = QueryPos.getInstance(q);
4507    
4508                    qPos.add(threadId);
4509    
4510                    if (orderByComparator != null) {
4511                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4512    
4513                            for (Object value : values) {
4514                                    qPos.add(value);
4515                            }
4516                    }
4517    
4518                    List<MBMessage> list = q.list();
4519    
4520                    if (list.size() == 2) {
4521                            return list.get(1);
4522                    }
4523                    else {
4524                            return null;
4525                    }
4526            }
4527    
4528            /**
4529             * Returns all the message-boards messages where userId = &#63;.
4530             *
4531             * @param userId the user ID
4532             * @return the matching message-boards messages
4533             * @throws SystemException if a system exception occurred
4534             */
4535            public List<MBMessage> findByUserId(long userId) throws SystemException {
4536                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4537            }
4538    
4539            /**
4540             * Returns a range of all the message-boards messages where userId = &#63;.
4541             *
4542             * <p>
4543             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4544             * </p>
4545             *
4546             * @param userId the user ID
4547             * @param start the lower bound of the range of message-boards messages
4548             * @param end the upper bound of the range of message-boards messages (not inclusive)
4549             * @return the range of matching message-boards messages
4550             * @throws SystemException if a system exception occurred
4551             */
4552            public List<MBMessage> findByUserId(long userId, int start, int end)
4553                    throws SystemException {
4554                    return findByUserId(userId, start, end, null);
4555            }
4556    
4557            /**
4558             * Returns an ordered range of all the message-boards messages where userId = &#63;.
4559             *
4560             * <p>
4561             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4562             * </p>
4563             *
4564             * @param userId the user ID
4565             * @param start the lower bound of the range of message-boards messages
4566             * @param end the upper bound of the range of message-boards messages (not inclusive)
4567             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4568             * @return the ordered range of matching message-boards messages
4569             * @throws SystemException if a system exception occurred
4570             */
4571            public List<MBMessage> findByUserId(long userId, int start, int end,
4572                    OrderByComparator orderByComparator) throws SystemException {
4573                    FinderPath finderPath = null;
4574                    Object[] finderArgs = null;
4575    
4576                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4577                                    (orderByComparator == null)) {
4578                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
4579                            finderArgs = new Object[] { userId };
4580                    }
4581                    else {
4582                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
4583                            finderArgs = new Object[] { userId, start, end, orderByComparator };
4584                    }
4585    
4586                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4587                                    finderArgs, this);
4588    
4589                    if ((list != null) && !list.isEmpty()) {
4590                            for (MBMessage mbMessage : list) {
4591                                    if ((userId != mbMessage.getUserId())) {
4592                                            list = null;
4593    
4594                                            break;
4595                                    }
4596                            }
4597                    }
4598    
4599                    if (list == null) {
4600                            StringBundler query = null;
4601    
4602                            if (orderByComparator != null) {
4603                                    query = new StringBundler(3 +
4604                                                    (orderByComparator.getOrderByFields().length * 3));
4605                            }
4606                            else {
4607                                    query = new StringBundler(3);
4608                            }
4609    
4610                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4611    
4612                            query.append(_FINDER_COLUMN_USERID_USERID_2);
4613    
4614                            if (orderByComparator != null) {
4615                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4616                                            orderByComparator);
4617                            }
4618    
4619                            else {
4620                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4621                            }
4622    
4623                            String sql = query.toString();
4624    
4625                            Session session = null;
4626    
4627                            try {
4628                                    session = openSession();
4629    
4630                                    Query q = session.createQuery(sql);
4631    
4632                                    QueryPos qPos = QueryPos.getInstance(q);
4633    
4634                                    qPos.add(userId);
4635    
4636                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
4637                                                    end);
4638                            }
4639                            catch (Exception e) {
4640                                    throw processException(e);
4641                            }
4642                            finally {
4643                                    if (list == null) {
4644                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4645                                    }
4646                                    else {
4647                                            cacheResult(list);
4648    
4649                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4650                                    }
4651    
4652                                    closeSession(session);
4653                            }
4654                    }
4655    
4656                    return list;
4657            }
4658    
4659            /**
4660             * Returns the first message-boards message in the ordered set where userId = &#63;.
4661             *
4662             * @param userId the user ID
4663             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4664             * @return the first matching message-boards message
4665             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4666             * @throws SystemException if a system exception occurred
4667             */
4668            public MBMessage findByUserId_First(long userId,
4669                    OrderByComparator orderByComparator)
4670                    throws NoSuchMessageException, SystemException {
4671                    MBMessage mbMessage = fetchByUserId_First(userId, orderByComparator);
4672    
4673                    if (mbMessage != null) {
4674                            return mbMessage;
4675                    }
4676    
4677                    StringBundler msg = new StringBundler(4);
4678    
4679                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4680    
4681                    msg.append("userId=");
4682                    msg.append(userId);
4683    
4684                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4685    
4686                    throw new NoSuchMessageException(msg.toString());
4687            }
4688    
4689            /**
4690             * Returns the first message-boards message in the ordered set where userId = &#63;.
4691             *
4692             * @param userId the user ID
4693             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4694             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4695             * @throws SystemException if a system exception occurred
4696             */
4697            public MBMessage fetchByUserId_First(long userId,
4698                    OrderByComparator orderByComparator) throws SystemException {
4699                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
4700    
4701                    if (!list.isEmpty()) {
4702                            return list.get(0);
4703                    }
4704    
4705                    return null;
4706            }
4707    
4708            /**
4709             * Returns the last message-boards message in the ordered set where userId = &#63;.
4710             *
4711             * @param userId the user ID
4712             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4713             * @return the last matching message-boards message
4714             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4715             * @throws SystemException if a system exception occurred
4716             */
4717            public MBMessage findByUserId_Last(long userId,
4718                    OrderByComparator orderByComparator)
4719                    throws NoSuchMessageException, SystemException {
4720                    MBMessage mbMessage = fetchByUserId_Last(userId, orderByComparator);
4721    
4722                    if (mbMessage != null) {
4723                            return mbMessage;
4724                    }
4725    
4726                    StringBundler msg = new StringBundler(4);
4727    
4728                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4729    
4730                    msg.append("userId=");
4731                    msg.append(userId);
4732    
4733                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4734    
4735                    throw new NoSuchMessageException(msg.toString());
4736            }
4737    
4738            /**
4739             * Returns the last message-boards message in the ordered set where userId = &#63;.
4740             *
4741             * @param userId the user ID
4742             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4743             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4744             * @throws SystemException if a system exception occurred
4745             */
4746            public MBMessage fetchByUserId_Last(long userId,
4747                    OrderByComparator orderByComparator) throws SystemException {
4748                    int count = countByUserId(userId);
4749    
4750                    List<MBMessage> list = findByUserId(userId, count - 1, count,
4751                                    orderByComparator);
4752    
4753                    if (!list.isEmpty()) {
4754                            return list.get(0);
4755                    }
4756    
4757                    return null;
4758            }
4759    
4760            /**
4761             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
4762             *
4763             * @param messageId the primary key of the current message-boards message
4764             * @param userId the user ID
4765             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4766             * @return the previous, current, and next message-boards message
4767             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4768             * @throws SystemException if a system exception occurred
4769             */
4770            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
4771                    OrderByComparator orderByComparator)
4772                    throws NoSuchMessageException, SystemException {
4773                    MBMessage mbMessage = findByPrimaryKey(messageId);
4774    
4775                    Session session = null;
4776    
4777                    try {
4778                            session = openSession();
4779    
4780                            MBMessage[] array = new MBMessageImpl[3];
4781    
4782                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
4783                                            orderByComparator, true);
4784    
4785                            array[1] = mbMessage;
4786    
4787                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
4788                                            orderByComparator, false);
4789    
4790                            return array;
4791                    }
4792                    catch (Exception e) {
4793                            throw processException(e);
4794                    }
4795                    finally {
4796                            closeSession(session);
4797                    }
4798            }
4799    
4800            protected MBMessage getByUserId_PrevAndNext(Session session,
4801                    MBMessage mbMessage, long userId, OrderByComparator orderByComparator,
4802                    boolean previous) {
4803                    StringBundler query = null;
4804    
4805                    if (orderByComparator != null) {
4806                            query = new StringBundler(6 +
4807                                            (orderByComparator.getOrderByFields().length * 6));
4808                    }
4809                    else {
4810                            query = new StringBundler(3);
4811                    }
4812    
4813                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4814    
4815                    query.append(_FINDER_COLUMN_USERID_USERID_2);
4816    
4817                    if (orderByComparator != null) {
4818                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4819    
4820                            if (orderByConditionFields.length > 0) {
4821                                    query.append(WHERE_AND);
4822                            }
4823    
4824                            for (int i = 0; i < orderByConditionFields.length; i++) {
4825                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4826                                    query.append(orderByConditionFields[i]);
4827    
4828                                    if ((i + 1) < orderByConditionFields.length) {
4829                                            if (orderByComparator.isAscending() ^ previous) {
4830                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4831                                            }
4832                                            else {
4833                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4834                                            }
4835                                    }
4836                                    else {
4837                                            if (orderByComparator.isAscending() ^ previous) {
4838                                                    query.append(WHERE_GREATER_THAN);
4839                                            }
4840                                            else {
4841                                                    query.append(WHERE_LESSER_THAN);
4842                                            }
4843                                    }
4844                            }
4845    
4846                            query.append(ORDER_BY_CLAUSE);
4847    
4848                            String[] orderByFields = orderByComparator.getOrderByFields();
4849    
4850                            for (int i = 0; i < orderByFields.length; i++) {
4851                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4852                                    query.append(orderByFields[i]);
4853    
4854                                    if ((i + 1) < orderByFields.length) {
4855                                            if (orderByComparator.isAscending() ^ previous) {
4856                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4857                                            }
4858                                            else {
4859                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4860                                            }
4861                                    }
4862                                    else {
4863                                            if (orderByComparator.isAscending() ^ previous) {
4864                                                    query.append(ORDER_BY_ASC);
4865                                            }
4866                                            else {
4867                                                    query.append(ORDER_BY_DESC);
4868                                            }
4869                                    }
4870                            }
4871                    }
4872    
4873                    else {
4874                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4875                    }
4876    
4877                    String sql = query.toString();
4878    
4879                    Query q = session.createQuery(sql);
4880    
4881                    q.setFirstResult(0);
4882                    q.setMaxResults(2);
4883    
4884                    QueryPos qPos = QueryPos.getInstance(q);
4885    
4886                    qPos.add(userId);
4887    
4888                    if (orderByComparator != null) {
4889                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4890    
4891                            for (Object value : values) {
4892                                    qPos.add(value);
4893                            }
4894                    }
4895    
4896                    List<MBMessage> list = q.list();
4897    
4898                    if (list.size() == 2) {
4899                            return list.get(1);
4900                    }
4901                    else {
4902                            return null;
4903                    }
4904            }
4905    
4906            /**
4907             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4908             *
4909             * @param groupId the group ID
4910             * @param userId the user ID
4911             * @return the matching message-boards messages
4912             * @throws SystemException if a system exception occurred
4913             */
4914            public List<MBMessage> findByG_U(long groupId, long userId)
4915                    throws SystemException {
4916                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4917                            null);
4918            }
4919    
4920            /**
4921             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4922             *
4923             * <p>
4924             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4925             * </p>
4926             *
4927             * @param groupId the group ID
4928             * @param userId the user ID
4929             * @param start the lower bound of the range of message-boards messages
4930             * @param end the upper bound of the range of message-boards messages (not inclusive)
4931             * @return the range of matching message-boards messages
4932             * @throws SystemException if a system exception occurred
4933             */
4934            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4935                    int end) throws SystemException {
4936                    return findByG_U(groupId, userId, start, end, null);
4937            }
4938    
4939            /**
4940             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4941             *
4942             * <p>
4943             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4944             * </p>
4945             *
4946             * @param groupId the group ID
4947             * @param userId the user ID
4948             * @param start the lower bound of the range of message-boards messages
4949             * @param end the upper bound of the range of message-boards messages (not inclusive)
4950             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4951             * @return the ordered range of matching message-boards messages
4952             * @throws SystemException if a system exception occurred
4953             */
4954            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4955                    int end, OrderByComparator orderByComparator) throws SystemException {
4956                    FinderPath finderPath = null;
4957                    Object[] finderArgs = null;
4958    
4959                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4960                                    (orderByComparator == null)) {
4961                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4962                            finderArgs = new Object[] { groupId, userId };
4963                    }
4964                    else {
4965                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4966                            finderArgs = new Object[] {
4967                                            groupId, userId,
4968                                            
4969                                            start, end, orderByComparator
4970                                    };
4971                    }
4972    
4973                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4974                                    finderArgs, this);
4975    
4976                    if ((list != null) && !list.isEmpty()) {
4977                            for (MBMessage mbMessage : list) {
4978                                    if ((groupId != mbMessage.getGroupId()) ||
4979                                                    (userId != mbMessage.getUserId())) {
4980                                            list = null;
4981    
4982                                            break;
4983                                    }
4984                            }
4985                    }
4986    
4987                    if (list == null) {
4988                            StringBundler query = null;
4989    
4990                            if (orderByComparator != null) {
4991                                    query = new StringBundler(4 +
4992                                                    (orderByComparator.getOrderByFields().length * 3));
4993                            }
4994                            else {
4995                                    query = new StringBundler(4);
4996                            }
4997    
4998                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4999    
5000                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5001    
5002                            query.append(_FINDER_COLUMN_G_U_USERID_2);
5003    
5004                            if (orderByComparator != null) {
5005                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5006                                            orderByComparator);
5007                            }
5008    
5009                            else {
5010                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5011                            }
5012    
5013                            String sql = query.toString();
5014    
5015                            Session session = null;
5016    
5017                            try {
5018                                    session = openSession();
5019    
5020                                    Query q = session.createQuery(sql);
5021    
5022                                    QueryPos qPos = QueryPos.getInstance(q);
5023    
5024                                    qPos.add(groupId);
5025    
5026                                    qPos.add(userId);
5027    
5028                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
5029                                                    end);
5030                            }
5031                            catch (Exception e) {
5032                                    throw processException(e);
5033                            }
5034                            finally {
5035                                    if (list == null) {
5036                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
5037                                    }
5038                                    else {
5039                                            cacheResult(list);
5040    
5041                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
5042                                    }
5043    
5044                                    closeSession(session);
5045                            }
5046                    }
5047    
5048                    return list;
5049            }
5050    
5051            /**
5052             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
5053             *
5054             * @param groupId the group ID
5055             * @param userId the user ID
5056             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5057             * @return the first matching message-boards message
5058             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5059             * @throws SystemException if a system exception occurred
5060             */
5061            public MBMessage findByG_U_First(long groupId, long userId,
5062                    OrderByComparator orderByComparator)
5063                    throws NoSuchMessageException, SystemException {
5064                    MBMessage mbMessage = fetchByG_U_First(groupId, userId,
5065                                    orderByComparator);
5066    
5067                    if (mbMessage != null) {
5068                            return mbMessage;
5069                    }
5070    
5071                    StringBundler msg = new StringBundler(6);
5072    
5073                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5074    
5075                    msg.append("groupId=");
5076                    msg.append(groupId);
5077    
5078                    msg.append(", userId=");
5079                    msg.append(userId);
5080    
5081                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5082    
5083                    throw new NoSuchMessageException(msg.toString());
5084            }
5085    
5086            /**
5087             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
5088             *
5089             * @param groupId the group ID
5090             * @param userId the user ID
5091             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5092             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5093             * @throws SystemException if a system exception occurred
5094             */
5095            public MBMessage fetchByG_U_First(long groupId, long userId,
5096                    OrderByComparator orderByComparator) throws SystemException {
5097                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
5098                                    orderByComparator);
5099    
5100                    if (!list.isEmpty()) {
5101                            return list.get(0);
5102                    }
5103    
5104                    return null;
5105            }
5106    
5107            /**
5108             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
5109             *
5110             * @param groupId the group ID
5111             * @param userId the user ID
5112             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5113             * @return the last matching message-boards message
5114             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5115             * @throws SystemException if a system exception occurred
5116             */
5117            public MBMessage findByG_U_Last(long groupId, long userId,
5118                    OrderByComparator orderByComparator)
5119                    throws NoSuchMessageException, SystemException {
5120                    MBMessage mbMessage = fetchByG_U_Last(groupId, userId, orderByComparator);
5121    
5122                    if (mbMessage != null) {
5123                            return mbMessage;
5124                    }
5125    
5126                    StringBundler msg = new StringBundler(6);
5127    
5128                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5129    
5130                    msg.append("groupId=");
5131                    msg.append(groupId);
5132    
5133                    msg.append(", userId=");
5134                    msg.append(userId);
5135    
5136                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5137    
5138                    throw new NoSuchMessageException(msg.toString());
5139            }
5140    
5141            /**
5142             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
5143             *
5144             * @param groupId the group ID
5145             * @param userId the user ID
5146             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5147             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5148             * @throws SystemException if a system exception occurred
5149             */
5150            public MBMessage fetchByG_U_Last(long groupId, long userId,
5151                    OrderByComparator orderByComparator) throws SystemException {
5152                    int count = countByG_U(groupId, userId);
5153    
5154                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
5155                                    orderByComparator);
5156    
5157                    if (!list.isEmpty()) {
5158                            return list.get(0);
5159                    }
5160    
5161                    return null;
5162            }
5163    
5164            /**
5165             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
5166             *
5167             * @param messageId the primary key of the current message-boards message
5168             * @param groupId the group ID
5169             * @param userId the user ID
5170             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5171             * @return the previous, current, and next message-boards message
5172             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5173             * @throws SystemException if a system exception occurred
5174             */
5175            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
5176                    long userId, OrderByComparator orderByComparator)
5177                    throws NoSuchMessageException, SystemException {
5178                    MBMessage mbMessage = findByPrimaryKey(messageId);
5179    
5180                    Session session = null;
5181    
5182                    try {
5183                            session = openSession();
5184    
5185                            MBMessage[] array = new MBMessageImpl[3];
5186    
5187                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
5188                                            userId, orderByComparator, true);
5189    
5190                            array[1] = mbMessage;
5191    
5192                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
5193                                            userId, orderByComparator, false);
5194    
5195                            return array;
5196                    }
5197                    catch (Exception e) {
5198                            throw processException(e);
5199                    }
5200                    finally {
5201                            closeSession(session);
5202                    }
5203            }
5204    
5205            protected MBMessage getByG_U_PrevAndNext(Session session,
5206                    MBMessage mbMessage, long groupId, long userId,
5207                    OrderByComparator orderByComparator, boolean previous) {
5208                    StringBundler query = null;
5209    
5210                    if (orderByComparator != null) {
5211                            query = new StringBundler(6 +
5212                                            (orderByComparator.getOrderByFields().length * 6));
5213                    }
5214                    else {
5215                            query = new StringBundler(3);
5216                    }
5217    
5218                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5219    
5220                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5221    
5222                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5223    
5224                    if (orderByComparator != null) {
5225                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5226    
5227                            if (orderByConditionFields.length > 0) {
5228                                    query.append(WHERE_AND);
5229                            }
5230    
5231                            for (int i = 0; i < orderByConditionFields.length; i++) {
5232                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5233                                    query.append(orderByConditionFields[i]);
5234    
5235                                    if ((i + 1) < orderByConditionFields.length) {
5236                                            if (orderByComparator.isAscending() ^ previous) {
5237                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5238                                            }
5239                                            else {
5240                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5241                                            }
5242                                    }
5243                                    else {
5244                                            if (orderByComparator.isAscending() ^ previous) {
5245                                                    query.append(WHERE_GREATER_THAN);
5246                                            }
5247                                            else {
5248                                                    query.append(WHERE_LESSER_THAN);
5249                                            }
5250                                    }
5251                            }
5252    
5253                            query.append(ORDER_BY_CLAUSE);
5254    
5255                            String[] orderByFields = orderByComparator.getOrderByFields();
5256    
5257                            for (int i = 0; i < orderByFields.length; i++) {
5258                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5259                                    query.append(orderByFields[i]);
5260    
5261                                    if ((i + 1) < orderByFields.length) {
5262                                            if (orderByComparator.isAscending() ^ previous) {
5263                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5264                                            }
5265                                            else {
5266                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5267                                            }
5268                                    }
5269                                    else {
5270                                            if (orderByComparator.isAscending() ^ previous) {
5271                                                    query.append(ORDER_BY_ASC);
5272                                            }
5273                                            else {
5274                                                    query.append(ORDER_BY_DESC);
5275                                            }
5276                                    }
5277                            }
5278                    }
5279    
5280                    else {
5281                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5282                    }
5283    
5284                    String sql = query.toString();
5285    
5286                    Query q = session.createQuery(sql);
5287    
5288                    q.setFirstResult(0);
5289                    q.setMaxResults(2);
5290    
5291                    QueryPos qPos = QueryPos.getInstance(q);
5292    
5293                    qPos.add(groupId);
5294    
5295                    qPos.add(userId);
5296    
5297                    if (orderByComparator != null) {
5298                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5299    
5300                            for (Object value : values) {
5301                                    qPos.add(value);
5302                            }
5303                    }
5304    
5305                    List<MBMessage> list = q.list();
5306    
5307                    if (list.size() == 2) {
5308                            return list.get(1);
5309                    }
5310                    else {
5311                            return null;
5312                    }
5313            }
5314    
5315            /**
5316             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
5317             *
5318             * @param groupId the group ID
5319             * @param userId the user ID
5320             * @return the matching message-boards messages that the user has permission to view
5321             * @throws SystemException if a system exception occurred
5322             */
5323            public List<MBMessage> filterFindByG_U(long groupId, long userId)
5324                    throws SystemException {
5325                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
5326                            QueryUtil.ALL_POS, null);
5327            }
5328    
5329            /**
5330             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
5331             *
5332             * <p>
5333             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5334             * </p>
5335             *
5336             * @param groupId the group ID
5337             * @param userId the user ID
5338             * @param start the lower bound of the range of message-boards messages
5339             * @param end the upper bound of the range of message-boards messages (not inclusive)
5340             * @return the range of matching message-boards messages that the user has permission to view
5341             * @throws SystemException if a system exception occurred
5342             */
5343            public List<MBMessage> filterFindByG_U(long groupId, long userId,
5344                    int start, int end) throws SystemException {
5345                    return filterFindByG_U(groupId, userId, start, end, null);
5346            }
5347    
5348            /**
5349             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
5350             *
5351             * <p>
5352             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5353             * </p>
5354             *
5355             * @param groupId the group ID
5356             * @param userId the user ID
5357             * @param start the lower bound of the range of message-boards messages
5358             * @param end the upper bound of the range of message-boards messages (not inclusive)
5359             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5360             * @return the ordered range of matching message-boards messages that the user has permission to view
5361             * @throws SystemException if a system exception occurred
5362             */
5363            public List<MBMessage> filterFindByG_U(long groupId, long userId,
5364                    int start, int end, OrderByComparator orderByComparator)
5365                    throws SystemException {
5366                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5367                            return findByG_U(groupId, userId, start, end, orderByComparator);
5368                    }
5369    
5370                    StringBundler query = null;
5371    
5372                    if (orderByComparator != null) {
5373                            query = new StringBundler(4 +
5374                                            (orderByComparator.getOrderByFields().length * 3));
5375                    }
5376                    else {
5377                            query = new StringBundler(4);
5378                    }
5379    
5380                    if (getDB().isSupportsInlineDistinct()) {
5381                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5382                    }
5383                    else {
5384                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5385                    }
5386    
5387                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5388    
5389                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5390    
5391                    if (!getDB().isSupportsInlineDistinct()) {
5392                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5393                    }
5394    
5395                    if (orderByComparator != null) {
5396                            if (getDB().isSupportsInlineDistinct()) {
5397                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5398                                            orderByComparator);
5399                            }
5400                            else {
5401                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5402                                            orderByComparator);
5403                            }
5404                    }
5405    
5406                    else {
5407                            if (getDB().isSupportsInlineDistinct()) {
5408                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5409                            }
5410                            else {
5411                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5412                            }
5413                    }
5414    
5415                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5416                                    MBMessage.class.getName(),
5417                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5418    
5419                    Session session = null;
5420    
5421                    try {
5422                            session = openSession();
5423    
5424                            SQLQuery q = session.createSQLQuery(sql);
5425    
5426                            if (getDB().isSupportsInlineDistinct()) {
5427                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5428                            }
5429                            else {
5430                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5431                            }
5432    
5433                            QueryPos qPos = QueryPos.getInstance(q);
5434    
5435                            qPos.add(groupId);
5436    
5437                            qPos.add(userId);
5438    
5439                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5440                    }
5441                    catch (Exception e) {
5442                            throw processException(e);
5443                    }
5444                    finally {
5445                            closeSession(session);
5446                    }
5447            }
5448    
5449            /**
5450             * 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;.
5451             *
5452             * @param messageId the primary key of the current message-boards message
5453             * @param groupId the group ID
5454             * @param userId the user ID
5455             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5456             * @return the previous, current, and next message-boards message
5457             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5458             * @throws SystemException if a system exception occurred
5459             */
5460            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
5461                    long groupId, long userId, OrderByComparator orderByComparator)
5462                    throws NoSuchMessageException, SystemException {
5463                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5464                            return findByG_U_PrevAndNext(messageId, groupId, userId,
5465                                    orderByComparator);
5466                    }
5467    
5468                    MBMessage mbMessage = findByPrimaryKey(messageId);
5469    
5470                    Session session = null;
5471    
5472                    try {
5473                            session = openSession();
5474    
5475                            MBMessage[] array = new MBMessageImpl[3];
5476    
5477                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
5478                                            userId, orderByComparator, true);
5479    
5480                            array[1] = mbMessage;
5481    
5482                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
5483                                            userId, orderByComparator, false);
5484    
5485                            return array;
5486                    }
5487                    catch (Exception e) {
5488                            throw processException(e);
5489                    }
5490                    finally {
5491                            closeSession(session);
5492                    }
5493            }
5494    
5495            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
5496                    MBMessage mbMessage, long groupId, long userId,
5497                    OrderByComparator orderByComparator, boolean previous) {
5498                    StringBundler query = null;
5499    
5500                    if (orderByComparator != null) {
5501                            query = new StringBundler(6 +
5502                                            (orderByComparator.getOrderByFields().length * 6));
5503                    }
5504                    else {
5505                            query = new StringBundler(3);
5506                    }
5507    
5508                    if (getDB().isSupportsInlineDistinct()) {
5509                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5510                    }
5511                    else {
5512                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5513                    }
5514    
5515                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5516    
5517                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5518    
5519                    if (!getDB().isSupportsInlineDistinct()) {
5520                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5521                    }
5522    
5523                    if (orderByComparator != null) {
5524                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5525    
5526                            if (orderByConditionFields.length > 0) {
5527                                    query.append(WHERE_AND);
5528                            }
5529    
5530                            for (int i = 0; i < orderByConditionFields.length; i++) {
5531                                    if (getDB().isSupportsInlineDistinct()) {
5532                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5533                                    }
5534                                    else {
5535                                            query.append(_ORDER_BY_ENTITY_TABLE);
5536                                    }
5537    
5538                                    query.append(orderByConditionFields[i]);
5539    
5540                                    if ((i + 1) < orderByConditionFields.length) {
5541                                            if (orderByComparator.isAscending() ^ previous) {
5542                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5543                                            }
5544                                            else {
5545                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5546                                            }
5547                                    }
5548                                    else {
5549                                            if (orderByComparator.isAscending() ^ previous) {
5550                                                    query.append(WHERE_GREATER_THAN);
5551                                            }
5552                                            else {
5553                                                    query.append(WHERE_LESSER_THAN);
5554                                            }
5555                                    }
5556                            }
5557    
5558                            query.append(ORDER_BY_CLAUSE);
5559    
5560                            String[] orderByFields = orderByComparator.getOrderByFields();
5561    
5562                            for (int i = 0; i < orderByFields.length; i++) {
5563                                    if (getDB().isSupportsInlineDistinct()) {
5564                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5565                                    }
5566                                    else {
5567                                            query.append(_ORDER_BY_ENTITY_TABLE);
5568                                    }
5569    
5570                                    query.append(orderByFields[i]);
5571    
5572                                    if ((i + 1) < orderByFields.length) {
5573                                            if (orderByComparator.isAscending() ^ previous) {
5574                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5575                                            }
5576                                            else {
5577                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5578                                            }
5579                                    }
5580                                    else {
5581                                            if (orderByComparator.isAscending() ^ previous) {
5582                                                    query.append(ORDER_BY_ASC);
5583                                            }
5584                                            else {
5585                                                    query.append(ORDER_BY_DESC);
5586                                            }
5587                                    }
5588                            }
5589                    }
5590    
5591                    else {
5592                            if (getDB().isSupportsInlineDistinct()) {
5593                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5594                            }
5595                            else {
5596                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5597                            }
5598                    }
5599    
5600                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5601                                    MBMessage.class.getName(),
5602                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5603    
5604                    SQLQuery q = session.createSQLQuery(sql);
5605    
5606                    q.setFirstResult(0);
5607                    q.setMaxResults(2);
5608    
5609                    if (getDB().isSupportsInlineDistinct()) {
5610                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5611                    }
5612                    else {
5613                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5614                    }
5615    
5616                    QueryPos qPos = QueryPos.getInstance(q);
5617    
5618                    qPos.add(groupId);
5619    
5620                    qPos.add(userId);
5621    
5622                    if (orderByComparator != null) {
5623                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5624    
5625                            for (Object value : values) {
5626                                    qPos.add(value);
5627                            }
5628                    }
5629    
5630                    List<MBMessage> list = q.list();
5631    
5632                    if (list.size() == 2) {
5633                            return list.get(1);
5634                    }
5635                    else {
5636                            return null;
5637                    }
5638            }
5639    
5640            /**
5641             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5642             *
5643             * @param groupId the group ID
5644             * @param categoryId the category ID
5645             * @return the matching message-boards messages
5646             * @throws SystemException if a system exception occurred
5647             */
5648            public List<MBMessage> findByG_C(long groupId, long categoryId)
5649                    throws SystemException {
5650                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5651                            QueryUtil.ALL_POS, null);
5652            }
5653    
5654            /**
5655             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5656             *
5657             * <p>
5658             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5659             * </p>
5660             *
5661             * @param groupId the group ID
5662             * @param categoryId the category ID
5663             * @param start the lower bound of the range of message-boards messages
5664             * @param end the upper bound of the range of message-boards messages (not inclusive)
5665             * @return the range of matching message-boards messages
5666             * @throws SystemException if a system exception occurred
5667             */
5668            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5669                    int end) throws SystemException {
5670                    return findByG_C(groupId, categoryId, start, end, null);
5671            }
5672    
5673            /**
5674             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5675             *
5676             * <p>
5677             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5678             * </p>
5679             *
5680             * @param groupId the group ID
5681             * @param categoryId the category ID
5682             * @param start the lower bound of the range of message-boards messages
5683             * @param end the upper bound of the range of message-boards messages (not inclusive)
5684             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5685             * @return the ordered range of matching message-boards messages
5686             * @throws SystemException if a system exception occurred
5687             */
5688            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5689                    int end, OrderByComparator orderByComparator) throws SystemException {
5690                    FinderPath finderPath = null;
5691                    Object[] finderArgs = null;
5692    
5693                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5694                                    (orderByComparator == null)) {
5695                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5696                            finderArgs = new Object[] { groupId, categoryId };
5697                    }
5698                    else {
5699                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5700                            finderArgs = new Object[] {
5701                                            groupId, categoryId,
5702                                            
5703                                            start, end, orderByComparator
5704                                    };
5705                    }
5706    
5707                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
5708                                    finderArgs, this);
5709    
5710                    if ((list != null) && !list.isEmpty()) {
5711                            for (MBMessage mbMessage : list) {
5712                                    if ((groupId != mbMessage.getGroupId()) ||
5713                                                    (categoryId != mbMessage.getCategoryId())) {
5714                                            list = null;
5715    
5716                                            break;
5717                                    }
5718                            }
5719                    }
5720    
5721                    if (list == null) {
5722                            StringBundler query = null;
5723    
5724                            if (orderByComparator != null) {
5725                                    query = new StringBundler(4 +
5726                                                    (orderByComparator.getOrderByFields().length * 3));
5727                            }
5728                            else {
5729                                    query = new StringBundler(4);
5730                            }
5731    
5732                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5733    
5734                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5735    
5736                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5737    
5738                            if (orderByComparator != null) {
5739                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5740                                            orderByComparator);
5741                            }
5742    
5743                            else {
5744                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5745                            }
5746    
5747                            String sql = query.toString();
5748    
5749                            Session session = null;
5750    
5751                            try {
5752                                    session = openSession();
5753    
5754                                    Query q = session.createQuery(sql);
5755    
5756                                    QueryPos qPos = QueryPos.getInstance(q);
5757    
5758                                    qPos.add(groupId);
5759    
5760                                    qPos.add(categoryId);
5761    
5762                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
5763                                                    end);
5764                            }
5765                            catch (Exception e) {
5766                                    throw processException(e);
5767                            }
5768                            finally {
5769                                    if (list == null) {
5770                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
5771                                    }
5772                                    else {
5773                                            cacheResult(list);
5774    
5775                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
5776                                    }
5777    
5778                                    closeSession(session);
5779                            }
5780                    }
5781    
5782                    return list;
5783            }
5784    
5785            /**
5786             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5787             *
5788             * @param groupId the group ID
5789             * @param categoryId the category ID
5790             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5791             * @return the first matching message-boards message
5792             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5793             * @throws SystemException if a system exception occurred
5794             */
5795            public MBMessage findByG_C_First(long groupId, long categoryId,
5796                    OrderByComparator orderByComparator)
5797                    throws NoSuchMessageException, SystemException {
5798                    MBMessage mbMessage = fetchByG_C_First(groupId, categoryId,
5799                                    orderByComparator);
5800    
5801                    if (mbMessage != null) {
5802                            return mbMessage;
5803                    }
5804    
5805                    StringBundler msg = new StringBundler(6);
5806    
5807                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5808    
5809                    msg.append("groupId=");
5810                    msg.append(groupId);
5811    
5812                    msg.append(", categoryId=");
5813                    msg.append(categoryId);
5814    
5815                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5816    
5817                    throw new NoSuchMessageException(msg.toString());
5818            }
5819    
5820            /**
5821             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5822             *
5823             * @param groupId the group ID
5824             * @param categoryId the category ID
5825             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5826             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5827             * @throws SystemException if a system exception occurred
5828             */
5829            public MBMessage fetchByG_C_First(long groupId, long categoryId,
5830                    OrderByComparator orderByComparator) throws SystemException {
5831                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5832                                    orderByComparator);
5833    
5834                    if (!list.isEmpty()) {
5835                            return list.get(0);
5836                    }
5837    
5838                    return null;
5839            }
5840    
5841            /**
5842             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5843             *
5844             * @param groupId the group ID
5845             * @param categoryId the category ID
5846             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5847             * @return the last matching message-boards message
5848             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5849             * @throws SystemException if a system exception occurred
5850             */
5851            public MBMessage findByG_C_Last(long groupId, long categoryId,
5852                    OrderByComparator orderByComparator)
5853                    throws NoSuchMessageException, SystemException {
5854                    MBMessage mbMessage = fetchByG_C_Last(groupId, categoryId,
5855                                    orderByComparator);
5856    
5857                    if (mbMessage != null) {
5858                            return mbMessage;
5859                    }
5860    
5861                    StringBundler msg = new StringBundler(6);
5862    
5863                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5864    
5865                    msg.append("groupId=");
5866                    msg.append(groupId);
5867    
5868                    msg.append(", categoryId=");
5869                    msg.append(categoryId);
5870    
5871                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5872    
5873                    throw new NoSuchMessageException(msg.toString());
5874            }
5875    
5876            /**
5877             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5878             *
5879             * @param groupId the group ID
5880             * @param categoryId the category ID
5881             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5882             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5883             * @throws SystemException if a system exception occurred
5884             */
5885            public MBMessage fetchByG_C_Last(long groupId, long categoryId,
5886                    OrderByComparator orderByComparator) throws SystemException {
5887                    int count = countByG_C(groupId, categoryId);
5888    
5889                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5890                                    orderByComparator);
5891    
5892                    if (!list.isEmpty()) {
5893                            return list.get(0);
5894                    }
5895    
5896                    return null;
5897            }
5898    
5899            /**
5900             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5901             *
5902             * @param messageId the primary key of the current message-boards message
5903             * @param groupId the group ID
5904             * @param categoryId the category ID
5905             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5906             * @return the previous, current, and next message-boards message
5907             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5908             * @throws SystemException if a system exception occurred
5909             */
5910            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5911                    long categoryId, OrderByComparator orderByComparator)
5912                    throws NoSuchMessageException, SystemException {
5913                    MBMessage mbMessage = findByPrimaryKey(messageId);
5914    
5915                    Session session = null;
5916    
5917                    try {
5918                            session = openSession();
5919    
5920                            MBMessage[] array = new MBMessageImpl[3];
5921    
5922                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5923                                            categoryId, orderByComparator, true);
5924    
5925                            array[1] = mbMessage;
5926    
5927                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5928                                            categoryId, orderByComparator, false);
5929    
5930                            return array;
5931                    }
5932                    catch (Exception e) {
5933                            throw processException(e);
5934                    }
5935                    finally {
5936                            closeSession(session);
5937                    }
5938            }
5939    
5940            protected MBMessage getByG_C_PrevAndNext(Session session,
5941                    MBMessage mbMessage, long groupId, long categoryId,
5942                    OrderByComparator orderByComparator, boolean previous) {
5943                    StringBundler query = null;
5944    
5945                    if (orderByComparator != null) {
5946                            query = new StringBundler(6 +
5947                                            (orderByComparator.getOrderByFields().length * 6));
5948                    }
5949                    else {
5950                            query = new StringBundler(3);
5951                    }
5952    
5953                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5954    
5955                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5956    
5957                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5958    
5959                    if (orderByComparator != null) {
5960                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5961    
5962                            if (orderByConditionFields.length > 0) {
5963                                    query.append(WHERE_AND);
5964                            }
5965    
5966                            for (int i = 0; i < orderByConditionFields.length; i++) {
5967                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5968                                    query.append(orderByConditionFields[i]);
5969    
5970                                    if ((i + 1) < orderByConditionFields.length) {
5971                                            if (orderByComparator.isAscending() ^ previous) {
5972                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5973                                            }
5974                                            else {
5975                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5976                                            }
5977                                    }
5978                                    else {
5979                                            if (orderByComparator.isAscending() ^ previous) {
5980                                                    query.append(WHERE_GREATER_THAN);
5981                                            }
5982                                            else {
5983                                                    query.append(WHERE_LESSER_THAN);
5984                                            }
5985                                    }
5986                            }
5987    
5988                            query.append(ORDER_BY_CLAUSE);
5989    
5990                            String[] orderByFields = orderByComparator.getOrderByFields();
5991    
5992                            for (int i = 0; i < orderByFields.length; i++) {
5993                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5994                                    query.append(orderByFields[i]);
5995    
5996                                    if ((i + 1) < orderByFields.length) {
5997                                            if (orderByComparator.isAscending() ^ previous) {
5998                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5999                                            }
6000                                            else {
6001                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6002                                            }
6003                                    }
6004                                    else {
6005                                            if (orderByComparator.isAscending() ^ previous) {
6006                                                    query.append(ORDER_BY_ASC);
6007                                            }
6008                                            else {
6009                                                    query.append(ORDER_BY_DESC);
6010                                            }
6011                                    }
6012                            }
6013                    }
6014    
6015                    else {
6016                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6017                    }
6018    
6019                    String sql = query.toString();
6020    
6021                    Query q = session.createQuery(sql);
6022    
6023                    q.setFirstResult(0);
6024                    q.setMaxResults(2);
6025    
6026                    QueryPos qPos = QueryPos.getInstance(q);
6027    
6028                    qPos.add(groupId);
6029    
6030                    qPos.add(categoryId);
6031    
6032                    if (orderByComparator != null) {
6033                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6034    
6035                            for (Object value : values) {
6036                                    qPos.add(value);
6037                            }
6038                    }
6039    
6040                    List<MBMessage> list = q.list();
6041    
6042                    if (list.size() == 2) {
6043                            return list.get(1);
6044                    }
6045                    else {
6046                            return null;
6047                    }
6048            }
6049    
6050            /**
6051             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
6052             *
6053             * @param groupId the group ID
6054             * @param categoryId the category ID
6055             * @return the matching message-boards messages that the user has permission to view
6056             * @throws SystemException if a system exception occurred
6057             */
6058            public List<MBMessage> filterFindByG_C(long groupId, long categoryId)
6059                    throws SystemException {
6060                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
6061                            QueryUtil.ALL_POS, null);
6062            }
6063    
6064            /**
6065             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
6066             *
6067             * <p>
6068             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6069             * </p>
6070             *
6071             * @param groupId the group ID
6072             * @param categoryId the category ID
6073             * @param start the lower bound of the range of message-boards messages
6074             * @param end the upper bound of the range of message-boards messages (not inclusive)
6075             * @return the range of matching message-boards messages that the user has permission to view
6076             * @throws SystemException if a system exception occurred
6077             */
6078            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
6079                    int start, int end) throws SystemException {
6080                    return filterFindByG_C(groupId, categoryId, start, end, null);
6081            }
6082    
6083            /**
6084             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
6085             *
6086             * <p>
6087             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6088             * </p>
6089             *
6090             * @param groupId the group ID
6091             * @param categoryId the category ID
6092             * @param start the lower bound of the range of message-boards messages
6093             * @param end the upper bound of the range of message-boards messages (not inclusive)
6094             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6095             * @return the ordered range of matching message-boards messages that the user has permission to view
6096             * @throws SystemException if a system exception occurred
6097             */
6098            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
6099                    int start, int end, OrderByComparator orderByComparator)
6100                    throws SystemException {
6101                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6102                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
6103                    }
6104    
6105                    StringBundler query = null;
6106    
6107                    if (orderByComparator != null) {
6108                            query = new StringBundler(4 +
6109                                            (orderByComparator.getOrderByFields().length * 3));
6110                    }
6111                    else {
6112                            query = new StringBundler(4);
6113                    }
6114    
6115                    if (getDB().isSupportsInlineDistinct()) {
6116                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6117                    }
6118                    else {
6119                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6120                    }
6121    
6122                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6123    
6124                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
6125    
6126                    if (!getDB().isSupportsInlineDistinct()) {
6127                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6128                    }
6129    
6130                    if (orderByComparator != null) {
6131                            if (getDB().isSupportsInlineDistinct()) {
6132                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6133                                            orderByComparator);
6134                            }
6135                            else {
6136                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6137                                            orderByComparator);
6138                            }
6139                    }
6140    
6141                    else {
6142                            if (getDB().isSupportsInlineDistinct()) {
6143                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6144                            }
6145                            else {
6146                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6147                            }
6148                    }
6149    
6150                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6151                                    MBMessage.class.getName(),
6152                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6153    
6154                    Session session = null;
6155    
6156                    try {
6157                            session = openSession();
6158    
6159                            SQLQuery q = session.createSQLQuery(sql);
6160    
6161                            if (getDB().isSupportsInlineDistinct()) {
6162                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6163                            }
6164                            else {
6165                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6166                            }
6167    
6168                            QueryPos qPos = QueryPos.getInstance(q);
6169    
6170                            qPos.add(groupId);
6171    
6172                            qPos.add(categoryId);
6173    
6174                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6175                    }
6176                    catch (Exception e) {
6177                            throw processException(e);
6178                    }
6179                    finally {
6180                            closeSession(session);
6181                    }
6182            }
6183    
6184            /**
6185             * 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;.
6186             *
6187             * @param messageId the primary key of the current message-boards message
6188             * @param groupId the group ID
6189             * @param categoryId the category ID
6190             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6191             * @return the previous, current, and next message-boards message
6192             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6193             * @throws SystemException if a system exception occurred
6194             */
6195            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
6196                    long groupId, long categoryId, OrderByComparator orderByComparator)
6197                    throws NoSuchMessageException, SystemException {
6198                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6199                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
6200                                    orderByComparator);
6201                    }
6202    
6203                    MBMessage mbMessage = findByPrimaryKey(messageId);
6204    
6205                    Session session = null;
6206    
6207                    try {
6208                            session = openSession();
6209    
6210                            MBMessage[] array = new MBMessageImpl[3];
6211    
6212                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
6213                                            categoryId, orderByComparator, true);
6214    
6215                            array[1] = mbMessage;
6216    
6217                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
6218                                            categoryId, orderByComparator, false);
6219    
6220                            return array;
6221                    }
6222                    catch (Exception e) {
6223                            throw processException(e);
6224                    }
6225                    finally {
6226                            closeSession(session);
6227                    }
6228            }
6229    
6230            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
6231                    MBMessage mbMessage, long groupId, long categoryId,
6232                    OrderByComparator orderByComparator, boolean previous) {
6233                    StringBundler query = null;
6234    
6235                    if (orderByComparator != null) {
6236                            query = new StringBundler(6 +
6237                                            (orderByComparator.getOrderByFields().length * 6));
6238                    }
6239                    else {
6240                            query = new StringBundler(3);
6241                    }
6242    
6243                    if (getDB().isSupportsInlineDistinct()) {
6244                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6245                    }
6246                    else {
6247                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6248                    }
6249    
6250                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
6251    
6252                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
6253    
6254                    if (!getDB().isSupportsInlineDistinct()) {
6255                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6256                    }
6257    
6258                    if (orderByComparator != null) {
6259                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6260    
6261                            if (orderByConditionFields.length > 0) {
6262                                    query.append(WHERE_AND);
6263                            }
6264    
6265                            for (int i = 0; i < orderByConditionFields.length; i++) {
6266                                    if (getDB().isSupportsInlineDistinct()) {
6267                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6268                                    }
6269                                    else {
6270                                            query.append(_ORDER_BY_ENTITY_TABLE);
6271                                    }
6272    
6273                                    query.append(orderByConditionFields[i]);
6274    
6275                                    if ((i + 1) < orderByConditionFields.length) {
6276                                            if (orderByComparator.isAscending() ^ previous) {
6277                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6278                                            }
6279                                            else {
6280                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6281                                            }
6282                                    }
6283                                    else {
6284                                            if (orderByComparator.isAscending() ^ previous) {
6285                                                    query.append(WHERE_GREATER_THAN);
6286                                            }
6287                                            else {
6288                                                    query.append(WHERE_LESSER_THAN);
6289                                            }
6290                                    }
6291                            }
6292    
6293                            query.append(ORDER_BY_CLAUSE);
6294    
6295                            String[] orderByFields = orderByComparator.getOrderByFields();
6296    
6297                            for (int i = 0; i < orderByFields.length; i++) {
6298                                    if (getDB().isSupportsInlineDistinct()) {
6299                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6300                                    }
6301                                    else {
6302                                            query.append(_ORDER_BY_ENTITY_TABLE);
6303                                    }
6304    
6305                                    query.append(orderByFields[i]);
6306    
6307                                    if ((i + 1) < orderByFields.length) {
6308                                            if (orderByComparator.isAscending() ^ previous) {
6309                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6310                                            }
6311                                            else {
6312                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6313                                            }
6314                                    }
6315                                    else {
6316                                            if (orderByComparator.isAscending() ^ previous) {
6317                                                    query.append(ORDER_BY_ASC);
6318                                            }
6319                                            else {
6320                                                    query.append(ORDER_BY_DESC);
6321                                            }
6322                                    }
6323                            }
6324                    }
6325    
6326                    else {
6327                            if (getDB().isSupportsInlineDistinct()) {
6328                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6329                            }
6330                            else {
6331                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6332                            }
6333                    }
6334    
6335                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6336                                    MBMessage.class.getName(),
6337                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6338    
6339                    SQLQuery q = session.createSQLQuery(sql);
6340    
6341                    q.setFirstResult(0);
6342                    q.setMaxResults(2);
6343    
6344                    if (getDB().isSupportsInlineDistinct()) {
6345                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6346                    }
6347                    else {
6348                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6349                    }
6350    
6351                    QueryPos qPos = QueryPos.getInstance(q);
6352    
6353                    qPos.add(groupId);
6354    
6355                    qPos.add(categoryId);
6356    
6357                    if (orderByComparator != null) {
6358                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6359    
6360                            for (Object value : values) {
6361                                    qPos.add(value);
6362                            }
6363                    }
6364    
6365                    List<MBMessage> list = q.list();
6366    
6367                    if (list.size() == 2) {
6368                            return list.get(1);
6369                    }
6370                    else {
6371                            return null;
6372                    }
6373            }
6374    
6375            /**
6376             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
6377             *
6378             * @param groupId the group ID
6379             * @param status the status
6380             * @return the matching message-boards messages
6381             * @throws SystemException if a system exception occurred
6382             */
6383            public List<MBMessage> findByG_S(long groupId, int status)
6384                    throws SystemException {
6385                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
6386                            null);
6387            }
6388    
6389            /**
6390             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
6391             *
6392             * <p>
6393             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6394             * </p>
6395             *
6396             * @param groupId the group ID
6397             * @param status the status
6398             * @param start the lower bound of the range of message-boards messages
6399             * @param end the upper bound of the range of message-boards messages (not inclusive)
6400             * @return the range of matching message-boards messages
6401             * @throws SystemException if a system exception occurred
6402             */
6403            public List<MBMessage> findByG_S(long groupId, int status, int start,
6404                    int end) throws SystemException {
6405                    return findByG_S(groupId, status, start, end, null);
6406            }
6407    
6408            /**
6409             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6410             *
6411             * <p>
6412             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6413             * </p>
6414             *
6415             * @param groupId the group ID
6416             * @param status the status
6417             * @param start the lower bound of the range of message-boards messages
6418             * @param end the upper bound of the range of message-boards messages (not inclusive)
6419             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6420             * @return the ordered range of matching message-boards messages
6421             * @throws SystemException if a system exception occurred
6422             */
6423            public List<MBMessage> findByG_S(long groupId, int status, int start,
6424                    int end, OrderByComparator orderByComparator) throws SystemException {
6425                    FinderPath finderPath = null;
6426                    Object[] finderArgs = null;
6427    
6428                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6429                                    (orderByComparator == null)) {
6430                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
6431                            finderArgs = new Object[] { groupId, status };
6432                    }
6433                    else {
6434                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
6435                            finderArgs = new Object[] {
6436                                            groupId, status,
6437                                            
6438                                            start, end, orderByComparator
6439                                    };
6440                    }
6441    
6442                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6443                                    finderArgs, this);
6444    
6445                    if ((list != null) && !list.isEmpty()) {
6446                            for (MBMessage mbMessage : list) {
6447                                    if ((groupId != mbMessage.getGroupId()) ||
6448                                                    (status != mbMessage.getStatus())) {
6449                                            list = null;
6450    
6451                                            break;
6452                                    }
6453                            }
6454                    }
6455    
6456                    if (list == null) {
6457                            StringBundler query = null;
6458    
6459                            if (orderByComparator != null) {
6460                                    query = new StringBundler(4 +
6461                                                    (orderByComparator.getOrderByFields().length * 3));
6462                            }
6463                            else {
6464                                    query = new StringBundler(4);
6465                            }
6466    
6467                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6468    
6469                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6470    
6471                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6472    
6473                            if (orderByComparator != null) {
6474                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6475                                            orderByComparator);
6476                            }
6477    
6478                            else {
6479                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6480                            }
6481    
6482                            String sql = query.toString();
6483    
6484                            Session session = null;
6485    
6486                            try {
6487                                    session = openSession();
6488    
6489                                    Query q = session.createQuery(sql);
6490    
6491                                    QueryPos qPos = QueryPos.getInstance(q);
6492    
6493                                    qPos.add(groupId);
6494    
6495                                    qPos.add(status);
6496    
6497                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
6498                                                    end);
6499                            }
6500                            catch (Exception e) {
6501                                    throw processException(e);
6502                            }
6503                            finally {
6504                                    if (list == null) {
6505                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
6506                                    }
6507                                    else {
6508                                            cacheResult(list);
6509    
6510                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
6511                                    }
6512    
6513                                    closeSession(session);
6514                            }
6515                    }
6516    
6517                    return list;
6518            }
6519    
6520            /**
6521             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6522             *
6523             * @param groupId the group ID
6524             * @param status the status
6525             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6526             * @return the first matching message-boards message
6527             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6528             * @throws SystemException if a system exception occurred
6529             */
6530            public MBMessage findByG_S_First(long groupId, int status,
6531                    OrderByComparator orderByComparator)
6532                    throws NoSuchMessageException, SystemException {
6533                    MBMessage mbMessage = fetchByG_S_First(groupId, status,
6534                                    orderByComparator);
6535    
6536                    if (mbMessage != null) {
6537                            return mbMessage;
6538                    }
6539    
6540                    StringBundler msg = new StringBundler(6);
6541    
6542                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6543    
6544                    msg.append("groupId=");
6545                    msg.append(groupId);
6546    
6547                    msg.append(", status=");
6548                    msg.append(status);
6549    
6550                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6551    
6552                    throw new NoSuchMessageException(msg.toString());
6553            }
6554    
6555            /**
6556             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6557             *
6558             * @param groupId the group ID
6559             * @param status the status
6560             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6561             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6562             * @throws SystemException if a system exception occurred
6563             */
6564            public MBMessage fetchByG_S_First(long groupId, int status,
6565                    OrderByComparator orderByComparator) throws SystemException {
6566                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
6567                                    orderByComparator);
6568    
6569                    if (!list.isEmpty()) {
6570                            return list.get(0);
6571                    }
6572    
6573                    return null;
6574            }
6575    
6576            /**
6577             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6578             *
6579             * @param groupId the group ID
6580             * @param status the status
6581             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6582             * @return the last matching message-boards message
6583             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6584             * @throws SystemException if a system exception occurred
6585             */
6586            public MBMessage findByG_S_Last(long groupId, int status,
6587                    OrderByComparator orderByComparator)
6588                    throws NoSuchMessageException, SystemException {
6589                    MBMessage mbMessage = fetchByG_S_Last(groupId, status, orderByComparator);
6590    
6591                    if (mbMessage != null) {
6592                            return mbMessage;
6593                    }
6594    
6595                    StringBundler msg = new StringBundler(6);
6596    
6597                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6598    
6599                    msg.append("groupId=");
6600                    msg.append(groupId);
6601    
6602                    msg.append(", status=");
6603                    msg.append(status);
6604    
6605                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6606    
6607                    throw new NoSuchMessageException(msg.toString());
6608            }
6609    
6610            /**
6611             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6612             *
6613             * @param groupId the group ID
6614             * @param status the status
6615             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6616             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6617             * @throws SystemException if a system exception occurred
6618             */
6619            public MBMessage fetchByG_S_Last(long groupId, int status,
6620                    OrderByComparator orderByComparator) throws SystemException {
6621                    int count = countByG_S(groupId, status);
6622    
6623                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
6624                                    orderByComparator);
6625    
6626                    if (!list.isEmpty()) {
6627                            return list.get(0);
6628                    }
6629    
6630                    return null;
6631            }
6632    
6633            /**
6634             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6635             *
6636             * @param messageId the primary key of the current message-boards message
6637             * @param groupId the group ID
6638             * @param status the status
6639             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6640             * @return the previous, current, and next message-boards message
6641             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6642             * @throws SystemException if a system exception occurred
6643             */
6644            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
6645                    int status, OrderByComparator orderByComparator)
6646                    throws NoSuchMessageException, SystemException {
6647                    MBMessage mbMessage = findByPrimaryKey(messageId);
6648    
6649                    Session session = null;
6650    
6651                    try {
6652                            session = openSession();
6653    
6654                            MBMessage[] array = new MBMessageImpl[3];
6655    
6656                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6657                                            status, orderByComparator, true);
6658    
6659                            array[1] = mbMessage;
6660    
6661                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6662                                            status, orderByComparator, false);
6663    
6664                            return array;
6665                    }
6666                    catch (Exception e) {
6667                            throw processException(e);
6668                    }
6669                    finally {
6670                            closeSession(session);
6671                    }
6672            }
6673    
6674            protected MBMessage getByG_S_PrevAndNext(Session session,
6675                    MBMessage mbMessage, long groupId, int status,
6676                    OrderByComparator orderByComparator, boolean previous) {
6677                    StringBundler query = null;
6678    
6679                    if (orderByComparator != null) {
6680                            query = new StringBundler(6 +
6681                                            (orderByComparator.getOrderByFields().length * 6));
6682                    }
6683                    else {
6684                            query = new StringBundler(3);
6685                    }
6686    
6687                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6688    
6689                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6690    
6691                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6692    
6693                    if (orderByComparator != null) {
6694                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6695    
6696                            if (orderByConditionFields.length > 0) {
6697                                    query.append(WHERE_AND);
6698                            }
6699    
6700                            for (int i = 0; i < orderByConditionFields.length; i++) {
6701                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6702                                    query.append(orderByConditionFields[i]);
6703    
6704                                    if ((i + 1) < orderByConditionFields.length) {
6705                                            if (orderByComparator.isAscending() ^ previous) {
6706                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6707                                            }
6708                                            else {
6709                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6710                                            }
6711                                    }
6712                                    else {
6713                                            if (orderByComparator.isAscending() ^ previous) {
6714                                                    query.append(WHERE_GREATER_THAN);
6715                                            }
6716                                            else {
6717                                                    query.append(WHERE_LESSER_THAN);
6718                                            }
6719                                    }
6720                            }
6721    
6722                            query.append(ORDER_BY_CLAUSE);
6723    
6724                            String[] orderByFields = orderByComparator.getOrderByFields();
6725    
6726                            for (int i = 0; i < orderByFields.length; i++) {
6727                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6728                                    query.append(orderByFields[i]);
6729    
6730                                    if ((i + 1) < orderByFields.length) {
6731                                            if (orderByComparator.isAscending() ^ previous) {
6732                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6733                                            }
6734                                            else {
6735                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6736                                            }
6737                                    }
6738                                    else {
6739                                            if (orderByComparator.isAscending() ^ previous) {
6740                                                    query.append(ORDER_BY_ASC);
6741                                            }
6742                                            else {
6743                                                    query.append(ORDER_BY_DESC);
6744                                            }
6745                                    }
6746                            }
6747                    }
6748    
6749                    else {
6750                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6751                    }
6752    
6753                    String sql = query.toString();
6754    
6755                    Query q = session.createQuery(sql);
6756    
6757                    q.setFirstResult(0);
6758                    q.setMaxResults(2);
6759    
6760                    QueryPos qPos = QueryPos.getInstance(q);
6761    
6762                    qPos.add(groupId);
6763    
6764                    qPos.add(status);
6765    
6766                    if (orderByComparator != null) {
6767                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6768    
6769                            for (Object value : values) {
6770                                    qPos.add(value);
6771                            }
6772                    }
6773    
6774                    List<MBMessage> list = q.list();
6775    
6776                    if (list.size() == 2) {
6777                            return list.get(1);
6778                    }
6779                    else {
6780                            return null;
6781                    }
6782            }
6783    
6784            /**
6785             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6786             *
6787             * @param groupId the group ID
6788             * @param status the status
6789             * @return the matching message-boards messages that the user has permission to view
6790             * @throws SystemException if a system exception occurred
6791             */
6792            public List<MBMessage> filterFindByG_S(long groupId, int status)
6793                    throws SystemException {
6794                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6795                            QueryUtil.ALL_POS, null);
6796            }
6797    
6798            /**
6799             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6800             *
6801             * <p>
6802             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6803             * </p>
6804             *
6805             * @param groupId the group ID
6806             * @param status the status
6807             * @param start the lower bound of the range of message-boards messages
6808             * @param end the upper bound of the range of message-boards messages (not inclusive)
6809             * @return the range of matching message-boards messages that the user has permission to view
6810             * @throws SystemException if a system exception occurred
6811             */
6812            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6813                    int end) throws SystemException {
6814                    return filterFindByG_S(groupId, status, start, end, null);
6815            }
6816    
6817            /**
6818             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
6819             *
6820             * <p>
6821             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6822             * </p>
6823             *
6824             * @param groupId the group ID
6825             * @param status the status
6826             * @param start the lower bound of the range of message-boards messages
6827             * @param end the upper bound of the range of message-boards messages (not inclusive)
6828             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6829             * @return the ordered range of matching message-boards messages that the user has permission to view
6830             * @throws SystemException if a system exception occurred
6831             */
6832            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6833                    int end, OrderByComparator orderByComparator) throws SystemException {
6834                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6835                            return findByG_S(groupId, status, start, end, orderByComparator);
6836                    }
6837    
6838                    StringBundler query = null;
6839    
6840                    if (orderByComparator != null) {
6841                            query = new StringBundler(4 +
6842                                            (orderByComparator.getOrderByFields().length * 3));
6843                    }
6844                    else {
6845                            query = new StringBundler(4);
6846                    }
6847    
6848                    if (getDB().isSupportsInlineDistinct()) {
6849                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6850                    }
6851                    else {
6852                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6853                    }
6854    
6855                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6856    
6857                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6858    
6859                    if (!getDB().isSupportsInlineDistinct()) {
6860                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6861                    }
6862    
6863                    if (orderByComparator != null) {
6864                            if (getDB().isSupportsInlineDistinct()) {
6865                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6866                                            orderByComparator);
6867                            }
6868                            else {
6869                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6870                                            orderByComparator);
6871                            }
6872                    }
6873    
6874                    else {
6875                            if (getDB().isSupportsInlineDistinct()) {
6876                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6877                            }
6878                            else {
6879                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6880                            }
6881                    }
6882    
6883                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6884                                    MBMessage.class.getName(),
6885                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6886    
6887                    Session session = null;
6888    
6889                    try {
6890                            session = openSession();
6891    
6892                            SQLQuery q = session.createSQLQuery(sql);
6893    
6894                            if (getDB().isSupportsInlineDistinct()) {
6895                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6896                            }
6897                            else {
6898                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6899                            }
6900    
6901                            QueryPos qPos = QueryPos.getInstance(q);
6902    
6903                            qPos.add(groupId);
6904    
6905                            qPos.add(status);
6906    
6907                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6908                    }
6909                    catch (Exception e) {
6910                            throw processException(e);
6911                    }
6912                    finally {
6913                            closeSession(session);
6914                    }
6915            }
6916    
6917            /**
6918             * 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;.
6919             *
6920             * @param messageId the primary key of the current message-boards message
6921             * @param groupId the group ID
6922             * @param status the status
6923             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6924             * @return the previous, current, and next message-boards message
6925             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6926             * @throws SystemException if a system exception occurred
6927             */
6928            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6929                    long groupId, int status, OrderByComparator orderByComparator)
6930                    throws NoSuchMessageException, SystemException {
6931                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6932                            return findByG_S_PrevAndNext(messageId, groupId, status,
6933                                    orderByComparator);
6934                    }
6935    
6936                    MBMessage mbMessage = findByPrimaryKey(messageId);
6937    
6938                    Session session = null;
6939    
6940                    try {
6941                            session = openSession();
6942    
6943                            MBMessage[] array = new MBMessageImpl[3];
6944    
6945                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6946                                            status, orderByComparator, true);
6947    
6948                            array[1] = mbMessage;
6949    
6950                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6951                                            status, orderByComparator, false);
6952    
6953                            return array;
6954                    }
6955                    catch (Exception e) {
6956                            throw processException(e);
6957                    }
6958                    finally {
6959                            closeSession(session);
6960                    }
6961            }
6962    
6963            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6964                    MBMessage mbMessage, long groupId, int status,
6965                    OrderByComparator orderByComparator, boolean previous) {
6966                    StringBundler query = null;
6967    
6968                    if (orderByComparator != null) {
6969                            query = new StringBundler(6 +
6970                                            (orderByComparator.getOrderByFields().length * 6));
6971                    }
6972                    else {
6973                            query = new StringBundler(3);
6974                    }
6975    
6976                    if (getDB().isSupportsInlineDistinct()) {
6977                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6978                    }
6979                    else {
6980                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6981                    }
6982    
6983                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6984    
6985                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6986    
6987                    if (!getDB().isSupportsInlineDistinct()) {
6988                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6989                    }
6990    
6991                    if (orderByComparator != null) {
6992                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6993    
6994                            if (orderByConditionFields.length > 0) {
6995                                    query.append(WHERE_AND);
6996                            }
6997    
6998                            for (int i = 0; i < orderByConditionFields.length; i++) {
6999                                    if (getDB().isSupportsInlineDistinct()) {
7000                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7001                                    }
7002                                    else {
7003                                            query.append(_ORDER_BY_ENTITY_TABLE);
7004                                    }
7005    
7006                                    query.append(orderByConditionFields[i]);
7007    
7008                                    if ((i + 1) < orderByConditionFields.length) {
7009                                            if (orderByComparator.isAscending() ^ previous) {
7010                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7011                                            }
7012                                            else {
7013                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7014                                            }
7015                                    }
7016                                    else {
7017                                            if (orderByComparator.isAscending() ^ previous) {
7018                                                    query.append(WHERE_GREATER_THAN);
7019                                            }
7020                                            else {
7021                                                    query.append(WHERE_LESSER_THAN);
7022                                            }
7023                                    }
7024                            }
7025    
7026                            query.append(ORDER_BY_CLAUSE);
7027    
7028                            String[] orderByFields = orderByComparator.getOrderByFields();
7029    
7030                            for (int i = 0; i < orderByFields.length; i++) {
7031                                    if (getDB().isSupportsInlineDistinct()) {
7032                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7033                                    }
7034                                    else {
7035                                            query.append(_ORDER_BY_ENTITY_TABLE);
7036                                    }
7037    
7038                                    query.append(orderByFields[i]);
7039    
7040                                    if ((i + 1) < orderByFields.length) {
7041                                            if (orderByComparator.isAscending() ^ previous) {
7042                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7043                                            }
7044                                            else {
7045                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7046                                            }
7047                                    }
7048                                    else {
7049                                            if (orderByComparator.isAscending() ^ previous) {
7050                                                    query.append(ORDER_BY_ASC);
7051                                            }
7052                                            else {
7053                                                    query.append(ORDER_BY_DESC);
7054                                            }
7055                                    }
7056                            }
7057                    }
7058    
7059                    else {
7060                            if (getDB().isSupportsInlineDistinct()) {
7061                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7062                            }
7063                            else {
7064                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
7065                            }
7066                    }
7067    
7068                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7069                                    MBMessage.class.getName(),
7070                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7071    
7072                    SQLQuery q = session.createSQLQuery(sql);
7073    
7074                    q.setFirstResult(0);
7075                    q.setMaxResults(2);
7076    
7077                    if (getDB().isSupportsInlineDistinct()) {
7078                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
7079                    }
7080                    else {
7081                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
7082                    }
7083    
7084                    QueryPos qPos = QueryPos.getInstance(q);
7085    
7086                    qPos.add(groupId);
7087    
7088                    qPos.add(status);
7089    
7090                    if (orderByComparator != null) {
7091                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7092    
7093                            for (Object value : values) {
7094                                    qPos.add(value);
7095                            }
7096                    }
7097    
7098                    List<MBMessage> list = q.list();
7099    
7100                    if (list.size() == 2) {
7101                            return list.get(1);
7102                    }
7103                    else {
7104                            return null;
7105                    }
7106            }
7107    
7108            /**
7109             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
7110             *
7111             * @param companyId the company ID
7112             * @param status the status
7113             * @return the matching message-boards messages
7114             * @throws SystemException if a system exception occurred
7115             */
7116            public List<MBMessage> findByC_S(long companyId, int status)
7117                    throws SystemException {
7118                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
7119                            QueryUtil.ALL_POS, null);
7120            }
7121    
7122            /**
7123             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
7124             *
7125             * <p>
7126             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7127             * </p>
7128             *
7129             * @param companyId the company ID
7130             * @param status the status
7131             * @param start the lower bound of the range of message-boards messages
7132             * @param end the upper bound of the range of message-boards messages (not inclusive)
7133             * @return the range of matching message-boards messages
7134             * @throws SystemException if a system exception occurred
7135             */
7136            public List<MBMessage> findByC_S(long companyId, int status, int start,
7137                    int end) throws SystemException {
7138                    return findByC_S(companyId, status, start, end, null);
7139            }
7140    
7141            /**
7142             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
7143             *
7144             * <p>
7145             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7146             * </p>
7147             *
7148             * @param companyId the company ID
7149             * @param status the status
7150             * @param start the lower bound of the range of message-boards messages
7151             * @param end the upper bound of the range of message-boards messages (not inclusive)
7152             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7153             * @return the ordered range of matching message-boards messages
7154             * @throws SystemException if a system exception occurred
7155             */
7156            public List<MBMessage> findByC_S(long companyId, int status, int start,
7157                    int end, OrderByComparator orderByComparator) throws SystemException {
7158                    FinderPath finderPath = null;
7159                    Object[] finderArgs = null;
7160    
7161                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7162                                    (orderByComparator == null)) {
7163                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
7164                            finderArgs = new Object[] { companyId, status };
7165                    }
7166                    else {
7167                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
7168                            finderArgs = new Object[] {
7169                                            companyId, status,
7170                                            
7171                                            start, end, orderByComparator
7172                                    };
7173                    }
7174    
7175                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7176                                    finderArgs, this);
7177    
7178                    if ((list != null) && !list.isEmpty()) {
7179                            for (MBMessage mbMessage : list) {
7180                                    if ((companyId != mbMessage.getCompanyId()) ||
7181                                                    (status != mbMessage.getStatus())) {
7182                                            list = null;
7183    
7184                                            break;
7185                                    }
7186                            }
7187                    }
7188    
7189                    if (list == null) {
7190                            StringBundler query = null;
7191    
7192                            if (orderByComparator != null) {
7193                                    query = new StringBundler(4 +
7194                                                    (orderByComparator.getOrderByFields().length * 3));
7195                            }
7196                            else {
7197                                    query = new StringBundler(4);
7198                            }
7199    
7200                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7201    
7202                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7203    
7204                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7205    
7206                            if (orderByComparator != null) {
7207                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7208                                            orderByComparator);
7209                            }
7210    
7211                            else {
7212                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7213                            }
7214    
7215                            String sql = query.toString();
7216    
7217                            Session session = null;
7218    
7219                            try {
7220                                    session = openSession();
7221    
7222                                    Query q = session.createQuery(sql);
7223    
7224                                    QueryPos qPos = QueryPos.getInstance(q);
7225    
7226                                    qPos.add(companyId);
7227    
7228                                    qPos.add(status);
7229    
7230                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7231                                                    end);
7232                            }
7233                            catch (Exception e) {
7234                                    throw processException(e);
7235                            }
7236                            finally {
7237                                    if (list == null) {
7238                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
7239                                    }
7240                                    else {
7241                                            cacheResult(list);
7242    
7243                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
7244                                    }
7245    
7246                                    closeSession(session);
7247                            }
7248                    }
7249    
7250                    return list;
7251            }
7252    
7253            /**
7254             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7255             *
7256             * @param companyId the company ID
7257             * @param status the status
7258             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7259             * @return the first matching message-boards message
7260             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7261             * @throws SystemException if a system exception occurred
7262             */
7263            public MBMessage findByC_S_First(long companyId, int status,
7264                    OrderByComparator orderByComparator)
7265                    throws NoSuchMessageException, SystemException {
7266                    MBMessage mbMessage = fetchByC_S_First(companyId, status,
7267                                    orderByComparator);
7268    
7269                    if (mbMessage != null) {
7270                            return mbMessage;
7271                    }
7272    
7273                    StringBundler msg = new StringBundler(6);
7274    
7275                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7276    
7277                    msg.append("companyId=");
7278                    msg.append(companyId);
7279    
7280                    msg.append(", status=");
7281                    msg.append(status);
7282    
7283                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7284    
7285                    throw new NoSuchMessageException(msg.toString());
7286            }
7287    
7288            /**
7289             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7290             *
7291             * @param companyId the company ID
7292             * @param status the status
7293             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7294             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7295             * @throws SystemException if a system exception occurred
7296             */
7297            public MBMessage fetchByC_S_First(long companyId, int status,
7298                    OrderByComparator orderByComparator) throws SystemException {
7299                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
7300                                    orderByComparator);
7301    
7302                    if (!list.isEmpty()) {
7303                            return list.get(0);
7304                    }
7305    
7306                    return null;
7307            }
7308    
7309            /**
7310             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7311             *
7312             * @param companyId the company ID
7313             * @param status the status
7314             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7315             * @return the last matching message-boards message
7316             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7317             * @throws SystemException if a system exception occurred
7318             */
7319            public MBMessage findByC_S_Last(long companyId, int status,
7320                    OrderByComparator orderByComparator)
7321                    throws NoSuchMessageException, SystemException {
7322                    MBMessage mbMessage = fetchByC_S_Last(companyId, status,
7323                                    orderByComparator);
7324    
7325                    if (mbMessage != null) {
7326                            return mbMessage;
7327                    }
7328    
7329                    StringBundler msg = new StringBundler(6);
7330    
7331                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7332    
7333                    msg.append("companyId=");
7334                    msg.append(companyId);
7335    
7336                    msg.append(", status=");
7337                    msg.append(status);
7338    
7339                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7340    
7341                    throw new NoSuchMessageException(msg.toString());
7342            }
7343    
7344            /**
7345             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7346             *
7347             * @param companyId the company ID
7348             * @param status the status
7349             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7350             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7351             * @throws SystemException if a system exception occurred
7352             */
7353            public MBMessage fetchByC_S_Last(long companyId, int status,
7354                    OrderByComparator orderByComparator) throws SystemException {
7355                    int count = countByC_S(companyId, status);
7356    
7357                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
7358                                    orderByComparator);
7359    
7360                    if (!list.isEmpty()) {
7361                            return list.get(0);
7362                    }
7363    
7364                    return null;
7365            }
7366    
7367            /**
7368             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7369             *
7370             * @param messageId the primary key of the current message-boards message
7371             * @param companyId the company ID
7372             * @param status the status
7373             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7374             * @return the previous, current, and next message-boards message
7375             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7376             * @throws SystemException if a system exception occurred
7377             */
7378            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
7379                    int status, OrderByComparator orderByComparator)
7380                    throws NoSuchMessageException, SystemException {
7381                    MBMessage mbMessage = findByPrimaryKey(messageId);
7382    
7383                    Session session = null;
7384    
7385                    try {
7386                            session = openSession();
7387    
7388                            MBMessage[] array = new MBMessageImpl[3];
7389    
7390                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7391                                            status, orderByComparator, true);
7392    
7393                            array[1] = mbMessage;
7394    
7395                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7396                                            status, orderByComparator, false);
7397    
7398                            return array;
7399                    }
7400                    catch (Exception e) {
7401                            throw processException(e);
7402                    }
7403                    finally {
7404                            closeSession(session);
7405                    }
7406            }
7407    
7408            protected MBMessage getByC_S_PrevAndNext(Session session,
7409                    MBMessage mbMessage, long companyId, int status,
7410                    OrderByComparator orderByComparator, boolean previous) {
7411                    StringBundler query = null;
7412    
7413                    if (orderByComparator != null) {
7414                            query = new StringBundler(6 +
7415                                            (orderByComparator.getOrderByFields().length * 6));
7416                    }
7417                    else {
7418                            query = new StringBundler(3);
7419                    }
7420    
7421                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7422    
7423                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7424    
7425                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
7426    
7427                    if (orderByComparator != null) {
7428                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7429    
7430                            if (orderByConditionFields.length > 0) {
7431                                    query.append(WHERE_AND);
7432                            }
7433    
7434                            for (int i = 0; i < orderByConditionFields.length; i++) {
7435                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7436                                    query.append(orderByConditionFields[i]);
7437    
7438                                    if ((i + 1) < orderByConditionFields.length) {
7439                                            if (orderByComparator.isAscending() ^ previous) {
7440                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7441                                            }
7442                                            else {
7443                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7444                                            }
7445                                    }
7446                                    else {
7447                                            if (orderByComparator.isAscending() ^ previous) {
7448                                                    query.append(WHERE_GREATER_THAN);
7449                                            }
7450                                            else {
7451                                                    query.append(WHERE_LESSER_THAN);
7452                                            }
7453                                    }
7454                            }
7455    
7456                            query.append(ORDER_BY_CLAUSE);
7457    
7458                            String[] orderByFields = orderByComparator.getOrderByFields();
7459    
7460                            for (int i = 0; i < orderByFields.length; i++) {
7461                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7462                                    query.append(orderByFields[i]);
7463    
7464                                    if ((i + 1) < orderByFields.length) {
7465                                            if (orderByComparator.isAscending() ^ previous) {
7466                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7467                                            }
7468                                            else {
7469                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7470                                            }
7471                                    }
7472                                    else {
7473                                            if (orderByComparator.isAscending() ^ previous) {
7474                                                    query.append(ORDER_BY_ASC);
7475                                            }
7476                                            else {
7477                                                    query.append(ORDER_BY_DESC);
7478                                            }
7479                                    }
7480                            }
7481                    }
7482    
7483                    else {
7484                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7485                    }
7486    
7487                    String sql = query.toString();
7488    
7489                    Query q = session.createQuery(sql);
7490    
7491                    q.setFirstResult(0);
7492                    q.setMaxResults(2);
7493    
7494                    QueryPos qPos = QueryPos.getInstance(q);
7495    
7496                    qPos.add(companyId);
7497    
7498                    qPos.add(status);
7499    
7500                    if (orderByComparator != null) {
7501                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7502    
7503                            for (Object value : values) {
7504                                    qPos.add(value);
7505                            }
7506                    }
7507    
7508                    List<MBMessage> list = q.list();
7509    
7510                    if (list.size() == 2) {
7511                            return list.get(1);
7512                    }
7513                    else {
7514                            return null;
7515                    }
7516            }
7517    
7518            /**
7519             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
7520             *
7521             * @param userId the user ID
7522             * @param classNameId the class name ID
7523             * @return the matching message-boards messages
7524             * @throws SystemException if a system exception occurred
7525             */
7526            public List<MBMessage> findByU_C(long userId, long classNameId)
7527                    throws SystemException {
7528                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
7529                            QueryUtil.ALL_POS, null);
7530            }
7531    
7532            /**
7533             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7534             *
7535             * <p>
7536             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7537             * </p>
7538             *
7539             * @param userId the user ID
7540             * @param classNameId the class name ID
7541             * @param start the lower bound of the range of message-boards messages
7542             * @param end the upper bound of the range of message-boards messages (not inclusive)
7543             * @return the range of matching message-boards messages
7544             * @throws SystemException if a system exception occurred
7545             */
7546            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7547                    int end) throws SystemException {
7548                    return findByU_C(userId, classNameId, start, end, null);
7549            }
7550    
7551            /**
7552             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7553             *
7554             * <p>
7555             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7556             * </p>
7557             *
7558             * @param userId the user ID
7559             * @param classNameId the class name ID
7560             * @param start the lower bound of the range of message-boards messages
7561             * @param end the upper bound of the range of message-boards messages (not inclusive)
7562             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7563             * @return the ordered range of matching message-boards messages
7564             * @throws SystemException if a system exception occurred
7565             */
7566            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7567                    int end, OrderByComparator orderByComparator) throws SystemException {
7568                    FinderPath finderPath = null;
7569                    Object[] finderArgs = null;
7570    
7571                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7572                                    (orderByComparator == null)) {
7573                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7574                            finderArgs = new Object[] { userId, classNameId };
7575                    }
7576                    else {
7577                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7578                            finderArgs = new Object[] {
7579                                            userId, classNameId,
7580                                            
7581                                            start, end, orderByComparator
7582                                    };
7583                    }
7584    
7585                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7586                                    finderArgs, this);
7587    
7588                    if ((list != null) && !list.isEmpty()) {
7589                            for (MBMessage mbMessage : list) {
7590                                    if ((userId != mbMessage.getUserId()) ||
7591                                                    (classNameId != mbMessage.getClassNameId())) {
7592                                            list = null;
7593    
7594                                            break;
7595                                    }
7596                            }
7597                    }
7598    
7599                    if (list == null) {
7600                            StringBundler query = null;
7601    
7602                            if (orderByComparator != null) {
7603                                    query = new StringBundler(4 +
7604                                                    (orderByComparator.getOrderByFields().length * 3));
7605                            }
7606                            else {
7607                                    query = new StringBundler(4);
7608                            }
7609    
7610                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7611    
7612                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7613    
7614                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7615    
7616                            if (orderByComparator != null) {
7617                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7618                                            orderByComparator);
7619                            }
7620    
7621                            else {
7622                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7623                            }
7624    
7625                            String sql = query.toString();
7626    
7627                            Session session = null;
7628    
7629                            try {
7630                                    session = openSession();
7631    
7632                                    Query q = session.createQuery(sql);
7633    
7634                                    QueryPos qPos = QueryPos.getInstance(q);
7635    
7636                                    qPos.add(userId);
7637    
7638                                    qPos.add(classNameId);
7639    
7640                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7641                                                    end);
7642                            }
7643                            catch (Exception e) {
7644                                    throw processException(e);
7645                            }
7646                            finally {
7647                                    if (list == null) {
7648                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
7649                                    }
7650                                    else {
7651                                            cacheResult(list);
7652    
7653                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
7654                                    }
7655    
7656                                    closeSession(session);
7657                            }
7658                    }
7659    
7660                    return list;
7661            }
7662    
7663            /**
7664             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7665             *
7666             * @param userId the user ID
7667             * @param classNameId the class name ID
7668             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7669             * @return the first matching message-boards message
7670             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7671             * @throws SystemException if a system exception occurred
7672             */
7673            public MBMessage findByU_C_First(long userId, long classNameId,
7674                    OrderByComparator orderByComparator)
7675                    throws NoSuchMessageException, SystemException {
7676                    MBMessage mbMessage = fetchByU_C_First(userId, classNameId,
7677                                    orderByComparator);
7678    
7679                    if (mbMessage != null) {
7680                            return mbMessage;
7681                    }
7682    
7683                    StringBundler msg = new StringBundler(6);
7684    
7685                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7686    
7687                    msg.append("userId=");
7688                    msg.append(userId);
7689    
7690                    msg.append(", classNameId=");
7691                    msg.append(classNameId);
7692    
7693                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7694    
7695                    throw new NoSuchMessageException(msg.toString());
7696            }
7697    
7698            /**
7699             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7700             *
7701             * @param userId the user ID
7702             * @param classNameId the class name ID
7703             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7704             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7705             * @throws SystemException if a system exception occurred
7706             */
7707            public MBMessage fetchByU_C_First(long userId, long classNameId,
7708                    OrderByComparator orderByComparator) throws SystemException {
7709                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
7710                                    orderByComparator);
7711    
7712                    if (!list.isEmpty()) {
7713                            return list.get(0);
7714                    }
7715    
7716                    return null;
7717            }
7718    
7719            /**
7720             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7721             *
7722             * @param userId the user ID
7723             * @param classNameId the class name ID
7724             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7725             * @return the last matching message-boards message
7726             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7727             * @throws SystemException if a system exception occurred
7728             */
7729            public MBMessage findByU_C_Last(long userId, long classNameId,
7730                    OrderByComparator orderByComparator)
7731                    throws NoSuchMessageException, SystemException {
7732                    MBMessage mbMessage = fetchByU_C_Last(userId, classNameId,
7733                                    orderByComparator);
7734    
7735                    if (mbMessage != null) {
7736                            return mbMessage;
7737                    }
7738    
7739                    StringBundler msg = new StringBundler(6);
7740    
7741                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7742    
7743                    msg.append("userId=");
7744                    msg.append(userId);
7745    
7746                    msg.append(", classNameId=");
7747                    msg.append(classNameId);
7748    
7749                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7750    
7751                    throw new NoSuchMessageException(msg.toString());
7752            }
7753    
7754            /**
7755             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7756             *
7757             * @param userId the user ID
7758             * @param classNameId the class name ID
7759             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7760             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7761             * @throws SystemException if a system exception occurred
7762             */
7763            public MBMessage fetchByU_C_Last(long userId, long classNameId,
7764                    OrderByComparator orderByComparator) throws SystemException {
7765                    int count = countByU_C(userId, classNameId);
7766    
7767                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
7768                                    orderByComparator);
7769    
7770                    if (!list.isEmpty()) {
7771                            return list.get(0);
7772                    }
7773    
7774                    return null;
7775            }
7776    
7777            /**
7778             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7779             *
7780             * @param messageId the primary key of the current message-boards message
7781             * @param userId the user ID
7782             * @param classNameId the class name ID
7783             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7784             * @return the previous, current, and next message-boards message
7785             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7786             * @throws SystemException if a system exception occurred
7787             */
7788            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7789                    long classNameId, OrderByComparator orderByComparator)
7790                    throws NoSuchMessageException, SystemException {
7791                    MBMessage mbMessage = findByPrimaryKey(messageId);
7792    
7793                    Session session = null;
7794    
7795                    try {
7796                            session = openSession();
7797    
7798                            MBMessage[] array = new MBMessageImpl[3];
7799    
7800                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
7801                                            classNameId, orderByComparator, true);
7802    
7803                            array[1] = mbMessage;
7804    
7805                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
7806                                            classNameId, orderByComparator, false);
7807    
7808                            return array;
7809                    }
7810                    catch (Exception e) {
7811                            throw processException(e);
7812                    }
7813                    finally {
7814                            closeSession(session);
7815                    }
7816            }
7817    
7818            protected MBMessage getByU_C_PrevAndNext(Session session,
7819                    MBMessage mbMessage, long userId, long classNameId,
7820                    OrderByComparator orderByComparator, boolean previous) {
7821                    StringBundler query = null;
7822    
7823                    if (orderByComparator != null) {
7824                            query = new StringBundler(6 +
7825                                            (orderByComparator.getOrderByFields().length * 6));
7826                    }
7827                    else {
7828                            query = new StringBundler(3);
7829                    }
7830    
7831                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7832    
7833                    query.append(_FINDER_COLUMN_U_C_USERID_2);
7834    
7835                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7836    
7837                    if (orderByComparator != null) {
7838                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7839    
7840                            if (orderByConditionFields.length > 0) {
7841                                    query.append(WHERE_AND);
7842                            }
7843    
7844                            for (int i = 0; i < orderByConditionFields.length; i++) {
7845                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7846                                    query.append(orderByConditionFields[i]);
7847    
7848                                    if ((i + 1) < orderByConditionFields.length) {
7849                                            if (orderByComparator.isAscending() ^ previous) {
7850                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7851                                            }
7852                                            else {
7853                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7854                                            }
7855                                    }
7856                                    else {
7857                                            if (orderByComparator.isAscending() ^ previous) {
7858                                                    query.append(WHERE_GREATER_THAN);
7859                                            }
7860                                            else {
7861                                                    query.append(WHERE_LESSER_THAN);
7862                                            }
7863                                    }
7864                            }
7865    
7866                            query.append(ORDER_BY_CLAUSE);
7867    
7868                            String[] orderByFields = orderByComparator.getOrderByFields();
7869    
7870                            for (int i = 0; i < orderByFields.length; i++) {
7871                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7872                                    query.append(orderByFields[i]);
7873    
7874                                    if ((i + 1) < orderByFields.length) {
7875                                            if (orderByComparator.isAscending() ^ previous) {
7876                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7877                                            }
7878                                            else {
7879                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7880                                            }
7881                                    }
7882                                    else {
7883                                            if (orderByComparator.isAscending() ^ previous) {
7884                                                    query.append(ORDER_BY_ASC);
7885                                            }
7886                                            else {
7887                                                    query.append(ORDER_BY_DESC);
7888                                            }
7889                                    }
7890                            }
7891                    }
7892    
7893                    else {
7894                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7895                    }
7896    
7897                    String sql = query.toString();
7898    
7899                    Query q = session.createQuery(sql);
7900    
7901                    q.setFirstResult(0);
7902                    q.setMaxResults(2);
7903    
7904                    QueryPos qPos = QueryPos.getInstance(q);
7905    
7906                    qPos.add(userId);
7907    
7908                    qPos.add(classNameId);
7909    
7910                    if (orderByComparator != null) {
7911                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7912    
7913                            for (Object value : values) {
7914                                    qPos.add(value);
7915                            }
7916                    }
7917    
7918                    List<MBMessage> list = q.list();
7919    
7920                    if (list.size() == 2) {
7921                            return list.get(1);
7922                    }
7923                    else {
7924                            return null;
7925                    }
7926            }
7927    
7928            /**
7929             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7930             *
7931             * <p>
7932             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7933             * </p>
7934             *
7935             * @param userId the user ID
7936             * @param classNameIds the class name IDs
7937             * @return the matching message-boards messages
7938             * @throws SystemException if a system exception occurred
7939             */
7940            public List<MBMessage> findByU_C(long userId, long[] classNameIds)
7941                    throws SystemException {
7942                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
7943                            QueryUtil.ALL_POS, null);
7944            }
7945    
7946            /**
7947             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#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 userId the user ID
7954             * @param classNameIds the class name IDs
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> findByU_C(long userId, long[] classNameIds,
7961                    int start, int end) throws SystemException {
7962                    return findByU_C(userId, classNameIds, start, end, null);
7963            }
7964    
7965            /**
7966             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#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 userId the user ID
7973             * @param classNameIds the class name IDs
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> findByU_C(long userId, long[] classNameIds,
7981                    int start, int end, OrderByComparator orderByComparator)
7982                    throws SystemException {
7983                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7984                    Object[] finderArgs = null;
7985    
7986                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7987                                    (orderByComparator == null)) {
7988                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
7989                    }
7990                    else {
7991                            finderArgs = new Object[] {
7992                                            userId, StringUtil.merge(classNameIds),
7993                                            
7994                                            start, end, orderByComparator
7995                                    };
7996                    }
7997    
7998                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7999                                    finderArgs, this);
8000    
8001                    if ((list != null) && !list.isEmpty()) {
8002                            for (MBMessage mbMessage : list) {
8003                                    if ((userId != mbMessage.getUserId()) ||
8004                                                    !ArrayUtil.contains(classNameIds,
8005                                                            mbMessage.getClassNameId())) {
8006                                            list = null;
8007    
8008                                            break;
8009                                    }
8010                            }
8011                    }
8012    
8013                    if (list == null) {
8014                            StringBundler query = new StringBundler();
8015    
8016                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8017    
8018                            boolean conjunctionable = false;
8019    
8020                            if (conjunctionable) {
8021                                    query.append(WHERE_AND);
8022                            }
8023    
8024                            query.append(_FINDER_COLUMN_U_C_USERID_5);
8025    
8026                            conjunctionable = true;
8027    
8028                            if ((classNameIds == null) || (classNameIds.length > 0)) {
8029                                    if (conjunctionable) {
8030                                            query.append(WHERE_AND);
8031                                    }
8032    
8033                                    query.append(StringPool.OPEN_PARENTHESIS);
8034    
8035                                    for (int i = 0; i < classNameIds.length; i++) {
8036                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
8037    
8038                                            if ((i + 1) < classNameIds.length) {
8039                                                    query.append(WHERE_OR);
8040                                            }
8041                                    }
8042    
8043                                    query.append(StringPool.CLOSE_PARENTHESIS);
8044    
8045                                    conjunctionable = true;
8046                            }
8047    
8048                            if (orderByComparator != null) {
8049                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8050                                            orderByComparator);
8051                            }
8052    
8053                            else {
8054                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8055                            }
8056    
8057                            String sql = query.toString();
8058    
8059                            Session session = null;
8060    
8061                            try {
8062                                    session = openSession();
8063    
8064                                    Query q = session.createQuery(sql);
8065    
8066                                    QueryPos qPos = QueryPos.getInstance(q);
8067    
8068                                    qPos.add(userId);
8069    
8070                                    if (classNameIds != null) {
8071                                            qPos.add(classNameIds);
8072                                    }
8073    
8074                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8075                                                    end);
8076                            }
8077                            catch (Exception e) {
8078                                    throw processException(e);
8079                            }
8080                            finally {
8081                                    if (list == null) {
8082                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
8083                                    }
8084                                    else {
8085                                            cacheResult(list);
8086    
8087                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
8088                                    }
8089    
8090                                    closeSession(session);
8091                            }
8092                    }
8093    
8094                    return list;
8095            }
8096    
8097            /**
8098             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8099             *
8100             * @param classNameId the class name ID
8101             * @param classPK the class p k
8102             * @return the matching message-boards messages
8103             * @throws SystemException if a system exception occurred
8104             */
8105            public List<MBMessage> findByC_C(long classNameId, long classPK)
8106                    throws SystemException {
8107                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
8108                            QueryUtil.ALL_POS, null);
8109            }
8110    
8111            /**
8112             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8113             *
8114             * <p>
8115             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8116             * </p>
8117             *
8118             * @param classNameId the class name ID
8119             * @param classPK the class p k
8120             * @param start the lower bound of the range of message-boards messages
8121             * @param end the upper bound of the range of message-boards messages (not inclusive)
8122             * @return the range of matching message-boards messages
8123             * @throws SystemException if a system exception occurred
8124             */
8125            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8126                    int end) throws SystemException {
8127                    return findByC_C(classNameId, classPK, start, end, null);
8128            }
8129    
8130            /**
8131             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8132             *
8133             * <p>
8134             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8135             * </p>
8136             *
8137             * @param classNameId the class name ID
8138             * @param classPK the class p k
8139             * @param start the lower bound of the range of message-boards messages
8140             * @param end the upper bound of the range of message-boards messages (not inclusive)
8141             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8142             * @return the ordered range of matching message-boards messages
8143             * @throws SystemException if a system exception occurred
8144             */
8145            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8146                    int end, OrderByComparator orderByComparator) throws SystemException {
8147                    FinderPath finderPath = null;
8148                    Object[] finderArgs = null;
8149    
8150                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8151                                    (orderByComparator == null)) {
8152                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
8153                            finderArgs = new Object[] { classNameId, classPK };
8154                    }
8155                    else {
8156                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
8157                            finderArgs = new Object[] {
8158                                            classNameId, classPK,
8159                                            
8160                                            start, end, orderByComparator
8161                                    };
8162                    }
8163    
8164                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8165                                    finderArgs, this);
8166    
8167                    if ((list != null) && !list.isEmpty()) {
8168                            for (MBMessage mbMessage : list) {
8169                                    if ((classNameId != mbMessage.getClassNameId()) ||
8170                                                    (classPK != mbMessage.getClassPK())) {
8171                                            list = null;
8172    
8173                                            break;
8174                                    }
8175                            }
8176                    }
8177    
8178                    if (list == null) {
8179                            StringBundler query = null;
8180    
8181                            if (orderByComparator != null) {
8182                                    query = new StringBundler(4 +
8183                                                    (orderByComparator.getOrderByFields().length * 3));
8184                            }
8185                            else {
8186                                    query = new StringBundler(4);
8187                            }
8188    
8189                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8190    
8191                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8192    
8193                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8194    
8195                            if (orderByComparator != null) {
8196                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8197                                            orderByComparator);
8198                            }
8199    
8200                            else {
8201                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8202                            }
8203    
8204                            String sql = query.toString();
8205    
8206                            Session session = null;
8207    
8208                            try {
8209                                    session = openSession();
8210    
8211                                    Query q = session.createQuery(sql);
8212    
8213                                    QueryPos qPos = QueryPos.getInstance(q);
8214    
8215                                    qPos.add(classNameId);
8216    
8217                                    qPos.add(classPK);
8218    
8219                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8220                                                    end);
8221                            }
8222                            catch (Exception e) {
8223                                    throw processException(e);
8224                            }
8225                            finally {
8226                                    if (list == null) {
8227                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
8228                                    }
8229                                    else {
8230                                            cacheResult(list);
8231    
8232                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
8233                                    }
8234    
8235                                    closeSession(session);
8236                            }
8237                    }
8238    
8239                    return list;
8240            }
8241    
8242            /**
8243             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8244             *
8245             * @param classNameId the class name ID
8246             * @param classPK the class p k
8247             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8248             * @return the first matching message-boards message
8249             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8250             * @throws SystemException if a system exception occurred
8251             */
8252            public MBMessage findByC_C_First(long classNameId, long classPK,
8253                    OrderByComparator orderByComparator)
8254                    throws NoSuchMessageException, SystemException {
8255                    MBMessage mbMessage = fetchByC_C_First(classNameId, classPK,
8256                                    orderByComparator);
8257    
8258                    if (mbMessage != null) {
8259                            return mbMessage;
8260                    }
8261    
8262                    StringBundler msg = new StringBundler(6);
8263    
8264                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8265    
8266                    msg.append("classNameId=");
8267                    msg.append(classNameId);
8268    
8269                    msg.append(", classPK=");
8270                    msg.append(classPK);
8271    
8272                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8273    
8274                    throw new NoSuchMessageException(msg.toString());
8275            }
8276    
8277            /**
8278             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8279             *
8280             * @param classNameId the class name ID
8281             * @param classPK the class p k
8282             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8283             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8284             * @throws SystemException if a system exception occurred
8285             */
8286            public MBMessage fetchByC_C_First(long classNameId, long classPK,
8287                    OrderByComparator orderByComparator) throws SystemException {
8288                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
8289                                    orderByComparator);
8290    
8291                    if (!list.isEmpty()) {
8292                            return list.get(0);
8293                    }
8294    
8295                    return null;
8296            }
8297    
8298            /**
8299             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8300             *
8301             * @param classNameId the class name ID
8302             * @param classPK the class p k
8303             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8304             * @return the last matching message-boards message
8305             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8306             * @throws SystemException if a system exception occurred
8307             */
8308            public MBMessage findByC_C_Last(long classNameId, long classPK,
8309                    OrderByComparator orderByComparator)
8310                    throws NoSuchMessageException, SystemException {
8311                    MBMessage mbMessage = fetchByC_C_Last(classNameId, classPK,
8312                                    orderByComparator);
8313    
8314                    if (mbMessage != null) {
8315                            return mbMessage;
8316                    }
8317    
8318                    StringBundler msg = new StringBundler(6);
8319    
8320                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8321    
8322                    msg.append("classNameId=");
8323                    msg.append(classNameId);
8324    
8325                    msg.append(", classPK=");
8326                    msg.append(classPK);
8327    
8328                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8329    
8330                    throw new NoSuchMessageException(msg.toString());
8331            }
8332    
8333            /**
8334             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8335             *
8336             * @param classNameId the class name ID
8337             * @param classPK the class p k
8338             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8339             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8340             * @throws SystemException if a system exception occurred
8341             */
8342            public MBMessage fetchByC_C_Last(long classNameId, long classPK,
8343                    OrderByComparator orderByComparator) throws SystemException {
8344                    int count = countByC_C(classNameId, classPK);
8345    
8346                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
8347                                    count, orderByComparator);
8348    
8349                    if (!list.isEmpty()) {
8350                            return list.get(0);
8351                    }
8352    
8353                    return null;
8354            }
8355    
8356            /**
8357             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8358             *
8359             * @param messageId the primary key of the current message-boards message
8360             * @param classNameId the class name ID
8361             * @param classPK the class p k
8362             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8363             * @return the previous, current, and next message-boards message
8364             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8365             * @throws SystemException if a system exception occurred
8366             */
8367            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
8368                    long classPK, OrderByComparator orderByComparator)
8369                    throws NoSuchMessageException, SystemException {
8370                    MBMessage mbMessage = findByPrimaryKey(messageId);
8371    
8372                    Session session = null;
8373    
8374                    try {
8375                            session = openSession();
8376    
8377                            MBMessage[] array = new MBMessageImpl[3];
8378    
8379                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8380                                            classPK, orderByComparator, true);
8381    
8382                            array[1] = mbMessage;
8383    
8384                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8385                                            classPK, orderByComparator, false);
8386    
8387                            return array;
8388                    }
8389                    catch (Exception e) {
8390                            throw processException(e);
8391                    }
8392                    finally {
8393                            closeSession(session);
8394                    }
8395            }
8396    
8397            protected MBMessage getByC_C_PrevAndNext(Session session,
8398                    MBMessage mbMessage, long classNameId, long classPK,
8399                    OrderByComparator orderByComparator, boolean previous) {
8400                    StringBundler query = null;
8401    
8402                    if (orderByComparator != null) {
8403                            query = new StringBundler(6 +
8404                                            (orderByComparator.getOrderByFields().length * 6));
8405                    }
8406                    else {
8407                            query = new StringBundler(3);
8408                    }
8409    
8410                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8411    
8412                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8413    
8414                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8415    
8416                    if (orderByComparator != null) {
8417                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8418    
8419                            if (orderByConditionFields.length > 0) {
8420                                    query.append(WHERE_AND);
8421                            }
8422    
8423                            for (int i = 0; i < orderByConditionFields.length; i++) {
8424                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8425                                    query.append(orderByConditionFields[i]);
8426    
8427                                    if ((i + 1) < orderByConditionFields.length) {
8428                                            if (orderByComparator.isAscending() ^ previous) {
8429                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8430                                            }
8431                                            else {
8432                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8433                                            }
8434                                    }
8435                                    else {
8436                                            if (orderByComparator.isAscending() ^ previous) {
8437                                                    query.append(WHERE_GREATER_THAN);
8438                                            }
8439                                            else {
8440                                                    query.append(WHERE_LESSER_THAN);
8441                                            }
8442                                    }
8443                            }
8444    
8445                            query.append(ORDER_BY_CLAUSE);
8446    
8447                            String[] orderByFields = orderByComparator.getOrderByFields();
8448    
8449                            for (int i = 0; i < orderByFields.length; i++) {
8450                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8451                                    query.append(orderByFields[i]);
8452    
8453                                    if ((i + 1) < orderByFields.length) {
8454                                            if (orderByComparator.isAscending() ^ previous) {
8455                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8456                                            }
8457                                            else {
8458                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8459                                            }
8460                                    }
8461                                    else {
8462                                            if (orderByComparator.isAscending() ^ previous) {
8463                                                    query.append(ORDER_BY_ASC);
8464                                            }
8465                                            else {
8466                                                    query.append(ORDER_BY_DESC);
8467                                            }
8468                                    }
8469                            }
8470                    }
8471    
8472                    else {
8473                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8474                    }
8475    
8476                    String sql = query.toString();
8477    
8478                    Query q = session.createQuery(sql);
8479    
8480                    q.setFirstResult(0);
8481                    q.setMaxResults(2);
8482    
8483                    QueryPos qPos = QueryPos.getInstance(q);
8484    
8485                    qPos.add(classNameId);
8486    
8487                    qPos.add(classPK);
8488    
8489                    if (orderByComparator != null) {
8490                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8491    
8492                            for (Object value : values) {
8493                                    qPos.add(value);
8494                            }
8495                    }
8496    
8497                    List<MBMessage> list = q.list();
8498    
8499                    if (list.size() == 2) {
8500                            return list.get(1);
8501                    }
8502                    else {
8503                            return null;
8504                    }
8505            }
8506    
8507            /**
8508             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8509             *
8510             * @param threadId the thread ID
8511             * @param parentMessageId the parent message ID
8512             * @return the matching message-boards messages
8513             * @throws SystemException if a system exception occurred
8514             */
8515            public List<MBMessage> findByT_P(long threadId, long parentMessageId)
8516                    throws SystemException {
8517                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
8518                            QueryUtil.ALL_POS, null);
8519            }
8520    
8521            /**
8522             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8523             *
8524             * <p>
8525             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8526             * </p>
8527             *
8528             * @param threadId the thread ID
8529             * @param parentMessageId the parent message ID
8530             * @param start the lower bound of the range of message-boards messages
8531             * @param end the upper bound of the range of message-boards messages (not inclusive)
8532             * @return the range of matching message-boards messages
8533             * @throws SystemException if a system exception occurred
8534             */
8535            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8536                    int start, int end) throws SystemException {
8537                    return findByT_P(threadId, parentMessageId, start, end, null);
8538            }
8539    
8540            /**
8541             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8542             *
8543             * <p>
8544             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8545             * </p>
8546             *
8547             * @param threadId the thread ID
8548             * @param parentMessageId the parent message ID
8549             * @param start the lower bound of the range of message-boards messages
8550             * @param end the upper bound of the range of message-boards messages (not inclusive)
8551             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8552             * @return the ordered range of matching message-boards messages
8553             * @throws SystemException if a system exception occurred
8554             */
8555            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8556                    int start, int end, OrderByComparator orderByComparator)
8557                    throws SystemException {
8558                    FinderPath finderPath = null;
8559                    Object[] finderArgs = null;
8560    
8561                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8562                                    (orderByComparator == null)) {
8563                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
8564                            finderArgs = new Object[] { threadId, parentMessageId };
8565                    }
8566                    else {
8567                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
8568                            finderArgs = new Object[] {
8569                                            threadId, parentMessageId,
8570                                            
8571                                            start, end, orderByComparator
8572                                    };
8573                    }
8574    
8575                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8576                                    finderArgs, this);
8577    
8578                    if ((list != null) && !list.isEmpty()) {
8579                            for (MBMessage mbMessage : list) {
8580                                    if ((threadId != mbMessage.getThreadId()) ||
8581                                                    (parentMessageId != mbMessage.getParentMessageId())) {
8582                                            list = null;
8583    
8584                                            break;
8585                                    }
8586                            }
8587                    }
8588    
8589                    if (list == null) {
8590                            StringBundler query = null;
8591    
8592                            if (orderByComparator != null) {
8593                                    query = new StringBundler(4 +
8594                                                    (orderByComparator.getOrderByFields().length * 3));
8595                            }
8596                            else {
8597                                    query = new StringBundler(4);
8598                            }
8599    
8600                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8601    
8602                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
8603    
8604                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8605    
8606                            if (orderByComparator != null) {
8607                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8608                                            orderByComparator);
8609                            }
8610    
8611                            else {
8612                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8613                            }
8614    
8615                            String sql = query.toString();
8616    
8617                            Session session = null;
8618    
8619                            try {
8620                                    session = openSession();
8621    
8622                                    Query q = session.createQuery(sql);
8623    
8624                                    QueryPos qPos = QueryPos.getInstance(q);
8625    
8626                                    qPos.add(threadId);
8627    
8628                                    qPos.add(parentMessageId);
8629    
8630                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8631                                                    end);
8632                            }
8633                            catch (Exception e) {
8634                                    throw processException(e);
8635                            }
8636                            finally {
8637                                    if (list == null) {
8638                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
8639                                    }
8640                                    else {
8641                                            cacheResult(list);
8642    
8643                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
8644                                    }
8645    
8646                                    closeSession(session);
8647                            }
8648                    }
8649    
8650                    return list;
8651            }
8652    
8653            /**
8654             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8655             *
8656             * @param threadId the thread ID
8657             * @param parentMessageId the parent message ID
8658             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8659             * @return the first matching message-boards message
8660             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8661             * @throws SystemException if a system exception occurred
8662             */
8663            public MBMessage findByT_P_First(long threadId, long parentMessageId,
8664                    OrderByComparator orderByComparator)
8665                    throws NoSuchMessageException, SystemException {
8666                    MBMessage mbMessage = fetchByT_P_First(threadId, parentMessageId,
8667                                    orderByComparator);
8668    
8669                    if (mbMessage != null) {
8670                            return mbMessage;
8671                    }
8672    
8673                    StringBundler msg = new StringBundler(6);
8674    
8675                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8676    
8677                    msg.append("threadId=");
8678                    msg.append(threadId);
8679    
8680                    msg.append(", parentMessageId=");
8681                    msg.append(parentMessageId);
8682    
8683                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8684    
8685                    throw new NoSuchMessageException(msg.toString());
8686            }
8687    
8688            /**
8689             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8690             *
8691             * @param threadId the thread ID
8692             * @param parentMessageId the parent message ID
8693             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8694             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8695             * @throws SystemException if a system exception occurred
8696             */
8697            public MBMessage fetchByT_P_First(long threadId, long parentMessageId,
8698                    OrderByComparator orderByComparator) throws SystemException {
8699                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
8700                                    orderByComparator);
8701    
8702                    if (!list.isEmpty()) {
8703                            return list.get(0);
8704                    }
8705    
8706                    return null;
8707            }
8708    
8709            /**
8710             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8711             *
8712             * @param threadId the thread ID
8713             * @param parentMessageId the parent message ID
8714             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8715             * @return the last matching message-boards message
8716             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8717             * @throws SystemException if a system exception occurred
8718             */
8719            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
8720                    OrderByComparator orderByComparator)
8721                    throws NoSuchMessageException, SystemException {
8722                    MBMessage mbMessage = fetchByT_P_Last(threadId, parentMessageId,
8723                                    orderByComparator);
8724    
8725                    if (mbMessage != null) {
8726                            return mbMessage;
8727                    }
8728    
8729                    StringBundler msg = new StringBundler(6);
8730    
8731                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8732    
8733                    msg.append("threadId=");
8734                    msg.append(threadId);
8735    
8736                    msg.append(", parentMessageId=");
8737                    msg.append(parentMessageId);
8738    
8739                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8740    
8741                    throw new NoSuchMessageException(msg.toString());
8742            }
8743    
8744            /**
8745             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8746             *
8747             * @param threadId the thread ID
8748             * @param parentMessageId the parent message ID
8749             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8750             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8751             * @throws SystemException if a system exception occurred
8752             */
8753            public MBMessage fetchByT_P_Last(long threadId, long parentMessageId,
8754                    OrderByComparator orderByComparator) throws SystemException {
8755                    int count = countByT_P(threadId, parentMessageId);
8756    
8757                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
8758                                    count, orderByComparator);
8759    
8760                    if (!list.isEmpty()) {
8761                            return list.get(0);
8762                    }
8763    
8764                    return null;
8765            }
8766    
8767            /**
8768             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8769             *
8770             * @param messageId the primary key of the current message-boards message
8771             * @param threadId the thread ID
8772             * @param parentMessageId the parent message ID
8773             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8774             * @return the previous, current, and next message-boards message
8775             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8776             * @throws SystemException if a system exception occurred
8777             */
8778            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
8779                    long parentMessageId, OrderByComparator orderByComparator)
8780                    throws NoSuchMessageException, SystemException {
8781                    MBMessage mbMessage = findByPrimaryKey(messageId);
8782    
8783                    Session session = null;
8784    
8785                    try {
8786                            session = openSession();
8787    
8788                            MBMessage[] array = new MBMessageImpl[3];
8789    
8790                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8791                                            parentMessageId, orderByComparator, true);
8792    
8793                            array[1] = mbMessage;
8794    
8795                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8796                                            parentMessageId, orderByComparator, false);
8797    
8798                            return array;
8799                    }
8800                    catch (Exception e) {
8801                            throw processException(e);
8802                    }
8803                    finally {
8804                            closeSession(session);
8805                    }
8806            }
8807    
8808            protected MBMessage getByT_P_PrevAndNext(Session session,
8809                    MBMessage mbMessage, long threadId, long parentMessageId,
8810                    OrderByComparator orderByComparator, boolean previous) {
8811                    StringBundler query = null;
8812    
8813                    if (orderByComparator != null) {
8814                            query = new StringBundler(6 +
8815                                            (orderByComparator.getOrderByFields().length * 6));
8816                    }
8817                    else {
8818                            query = new StringBundler(3);
8819                    }
8820    
8821                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8822    
8823                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
8824    
8825                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8826    
8827                    if (orderByComparator != null) {
8828                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8829    
8830                            if (orderByConditionFields.length > 0) {
8831                                    query.append(WHERE_AND);
8832                            }
8833    
8834                            for (int i = 0; i < orderByConditionFields.length; i++) {
8835                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8836                                    query.append(orderByConditionFields[i]);
8837    
8838                                    if ((i + 1) < orderByConditionFields.length) {
8839                                            if (orderByComparator.isAscending() ^ previous) {
8840                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8841                                            }
8842                                            else {
8843                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8844                                            }
8845                                    }
8846                                    else {
8847                                            if (orderByComparator.isAscending() ^ previous) {
8848                                                    query.append(WHERE_GREATER_THAN);
8849                                            }
8850                                            else {
8851                                                    query.append(WHERE_LESSER_THAN);
8852                                            }
8853                                    }
8854                            }
8855    
8856                            query.append(ORDER_BY_CLAUSE);
8857    
8858                            String[] orderByFields = orderByComparator.getOrderByFields();
8859    
8860                            for (int i = 0; i < orderByFields.length; i++) {
8861                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8862                                    query.append(orderByFields[i]);
8863    
8864                                    if ((i + 1) < orderByFields.length) {
8865                                            if (orderByComparator.isAscending() ^ previous) {
8866                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8867                                            }
8868                                            else {
8869                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8870                                            }
8871                                    }
8872                                    else {
8873                                            if (orderByComparator.isAscending() ^ previous) {
8874                                                    query.append(ORDER_BY_ASC);
8875                                            }
8876                                            else {
8877                                                    query.append(ORDER_BY_DESC);
8878                                            }
8879                                    }
8880                            }
8881                    }
8882    
8883                    else {
8884                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8885                    }
8886    
8887                    String sql = query.toString();
8888    
8889                    Query q = session.createQuery(sql);
8890    
8891                    q.setFirstResult(0);
8892                    q.setMaxResults(2);
8893    
8894                    QueryPos qPos = QueryPos.getInstance(q);
8895    
8896                    qPos.add(threadId);
8897    
8898                    qPos.add(parentMessageId);
8899    
8900                    if (orderByComparator != null) {
8901                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8902    
8903                            for (Object value : values) {
8904                                    qPos.add(value);
8905                            }
8906                    }
8907    
8908                    List<MBMessage> list = q.list();
8909    
8910                    if (list.size() == 2) {
8911                            return list.get(1);
8912                    }
8913                    else {
8914                            return null;
8915                    }
8916            }
8917    
8918            /**
8919             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
8920             *
8921             * @param threadId the thread ID
8922             * @param answer the answer
8923             * @return the matching message-boards messages
8924             * @throws SystemException if a system exception occurred
8925             */
8926            public List<MBMessage> findByT_A(long threadId, boolean answer)
8927                    throws SystemException {
8928                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
8929                            QueryUtil.ALL_POS, null);
8930            }
8931    
8932            /**
8933             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
8934             *
8935             * <p>
8936             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8937             * </p>
8938             *
8939             * @param threadId the thread ID
8940             * @param answer the answer
8941             * @param start the lower bound of the range of message-boards messages
8942             * @param end the upper bound of the range of message-boards messages (not inclusive)
8943             * @return the range of matching message-boards messages
8944             * @throws SystemException if a system exception occurred
8945             */
8946            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
8947                    int end) throws SystemException {
8948                    return findByT_A(threadId, answer, start, end, null);
8949            }
8950    
8951            /**
8952             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
8953             *
8954             * <p>
8955             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
8956             * </p>
8957             *
8958             * @param threadId the thread ID
8959             * @param answer the answer
8960             * @param start the lower bound of the range of message-boards messages
8961             * @param end the upper bound of the range of message-boards messages (not inclusive)
8962             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8963             * @return the ordered range of matching message-boards messages
8964             * @throws SystemException if a system exception occurred
8965             */
8966            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
8967                    int end, OrderByComparator orderByComparator) throws SystemException {
8968                    FinderPath finderPath = null;
8969                    Object[] finderArgs = null;
8970    
8971                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8972                                    (orderByComparator == null)) {
8973                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
8974                            finderArgs = new Object[] { threadId, answer };
8975                    }
8976                    else {
8977                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
8978                            finderArgs = new Object[] {
8979                                            threadId, answer,
8980                                            
8981                                            start, end, orderByComparator
8982                                    };
8983                    }
8984    
8985                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8986                                    finderArgs, this);
8987    
8988                    if ((list != null) && !list.isEmpty()) {
8989                            for (MBMessage mbMessage : list) {
8990                                    if ((threadId != mbMessage.getThreadId()) ||
8991                                                    (answer != mbMessage.getAnswer())) {
8992                                            list = null;
8993    
8994                                            break;
8995                                    }
8996                            }
8997                    }
8998    
8999                    if (list == null) {
9000                            StringBundler query = null;
9001    
9002                            if (orderByComparator != null) {
9003                                    query = new StringBundler(4 +
9004                                                    (orderByComparator.getOrderByFields().length * 3));
9005                            }
9006                            else {
9007                                    query = new StringBundler(4);
9008                            }
9009    
9010                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9011    
9012                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9013    
9014                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9015    
9016                            if (orderByComparator != null) {
9017                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9018                                            orderByComparator);
9019                            }
9020    
9021                            else {
9022                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9023                            }
9024    
9025                            String sql = query.toString();
9026    
9027                            Session session = null;
9028    
9029                            try {
9030                                    session = openSession();
9031    
9032                                    Query q = session.createQuery(sql);
9033    
9034                                    QueryPos qPos = QueryPos.getInstance(q);
9035    
9036                                    qPos.add(threadId);
9037    
9038                                    qPos.add(answer);
9039    
9040                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
9041                                                    end);
9042                            }
9043                            catch (Exception e) {
9044                                    throw processException(e);
9045                            }
9046                            finally {
9047                                    if (list == null) {
9048                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
9049                                    }
9050                                    else {
9051                                            cacheResult(list);
9052    
9053                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
9054                                    }
9055    
9056                                    closeSession(session);
9057                            }
9058                    }
9059    
9060                    return list;
9061            }
9062    
9063            /**
9064             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9065             *
9066             * @param threadId the thread ID
9067             * @param answer the answer
9068             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9069             * @return the first matching message-boards message
9070             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9071             * @throws SystemException if a system exception occurred
9072             */
9073            public MBMessage findByT_A_First(long threadId, boolean answer,
9074                    OrderByComparator orderByComparator)
9075                    throws NoSuchMessageException, SystemException {
9076                    MBMessage mbMessage = fetchByT_A_First(threadId, answer,
9077                                    orderByComparator);
9078    
9079                    if (mbMessage != null) {
9080                            return mbMessage;
9081                    }
9082    
9083                    StringBundler msg = new StringBundler(6);
9084    
9085                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9086    
9087                    msg.append("threadId=");
9088                    msg.append(threadId);
9089    
9090                    msg.append(", answer=");
9091                    msg.append(answer);
9092    
9093                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9094    
9095                    throw new NoSuchMessageException(msg.toString());
9096            }
9097    
9098            /**
9099             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9100             *
9101             * @param threadId the thread ID
9102             * @param answer the answer
9103             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9104             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9105             * @throws SystemException if a system exception occurred
9106             */
9107            public MBMessage fetchByT_A_First(long threadId, boolean answer,
9108                    OrderByComparator orderByComparator) throws SystemException {
9109                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
9110                                    orderByComparator);
9111    
9112                    if (!list.isEmpty()) {
9113                            return list.get(0);
9114                    }
9115    
9116                    return null;
9117            }
9118    
9119            /**
9120             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9121             *
9122             * @param threadId the thread ID
9123             * @param answer the answer
9124             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9125             * @return the last matching message-boards message
9126             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9127             * @throws SystemException if a system exception occurred
9128             */
9129            public MBMessage findByT_A_Last(long threadId, boolean answer,
9130                    OrderByComparator orderByComparator)
9131                    throws NoSuchMessageException, SystemException {
9132                    MBMessage mbMessage = fetchByT_A_Last(threadId, answer,
9133                                    orderByComparator);
9134    
9135                    if (mbMessage != null) {
9136                            return mbMessage;
9137                    }
9138    
9139                    StringBundler msg = new StringBundler(6);
9140    
9141                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9142    
9143                    msg.append("threadId=");
9144                    msg.append(threadId);
9145    
9146                    msg.append(", answer=");
9147                    msg.append(answer);
9148    
9149                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9150    
9151                    throw new NoSuchMessageException(msg.toString());
9152            }
9153    
9154            /**
9155             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9156             *
9157             * @param threadId the thread ID
9158             * @param answer the answer
9159             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9160             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9161             * @throws SystemException if a system exception occurred
9162             */
9163            public MBMessage fetchByT_A_Last(long threadId, boolean answer,
9164                    OrderByComparator orderByComparator) throws SystemException {
9165                    int count = countByT_A(threadId, answer);
9166    
9167                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
9168                                    orderByComparator);
9169    
9170                    if (!list.isEmpty()) {
9171                            return list.get(0);
9172                    }
9173    
9174                    return null;
9175            }
9176    
9177            /**
9178             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9179             *
9180             * @param messageId the primary key of the current message-boards message
9181             * @param threadId the thread ID
9182             * @param answer the answer
9183             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9184             * @return the previous, current, and next message-boards message
9185             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9186             * @throws SystemException if a system exception occurred
9187             */
9188            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
9189                    boolean answer, OrderByComparator orderByComparator)
9190                    throws NoSuchMessageException, SystemException {
9191                    MBMessage mbMessage = findByPrimaryKey(messageId);
9192    
9193                    Session session = null;
9194    
9195                    try {
9196                            session = openSession();
9197    
9198                            MBMessage[] array = new MBMessageImpl[3];
9199    
9200                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9201                                            answer, orderByComparator, true);
9202    
9203                            array[1] = mbMessage;
9204    
9205                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9206                                            answer, orderByComparator, false);
9207    
9208                            return array;
9209                    }
9210                    catch (Exception e) {
9211                            throw processException(e);
9212                    }
9213                    finally {
9214                            closeSession(session);
9215                    }
9216            }
9217    
9218            protected MBMessage getByT_A_PrevAndNext(Session session,
9219                    MBMessage mbMessage, long threadId, boolean answer,
9220                    OrderByComparator orderByComparator, boolean previous) {
9221                    StringBundler query = null;
9222    
9223                    if (orderByComparator != null) {
9224                            query = new StringBundler(6 +
9225                                            (orderByComparator.getOrderByFields().length * 6));
9226                    }
9227                    else {
9228                            query = new StringBundler(3);
9229                    }
9230    
9231                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9232    
9233                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
9234    
9235                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9236    
9237                    if (orderByComparator != null) {
9238                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9239    
9240                            if (orderByConditionFields.length > 0) {
9241                                    query.append(WHERE_AND);
9242                            }
9243    
9244                            for (int i = 0; i < orderByConditionFields.length; i++) {
9245                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9246                                    query.append(orderByConditionFields[i]);
9247    
9248                                    if ((i + 1) < orderByConditionFields.length) {
9249                                            if (orderByComparator.isAscending() ^ previous) {
9250                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9251                                            }
9252                                            else {
9253                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9254                                            }
9255                                    }
9256                                    else {
9257                                            if (orderByComparator.isAscending() ^ previous) {
9258                                                    query.append(WHERE_GREATER_THAN);
9259                                            }
9260                                            else {
9261                                                    query.append(WHERE_LESSER_THAN);
9262                                            }
9263                                    }
9264                            }
9265    
9266                            query.append(ORDER_BY_CLAUSE);
9267    
9268                            String[] orderByFields = orderByComparator.getOrderByFields();
9269    
9270                            for (int i = 0; i < orderByFields.length; i++) {
9271                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9272                                    query.append(orderByFields[i]);
9273    
9274                                    if ((i + 1) < orderByFields.length) {
9275                                            if (orderByComparator.isAscending() ^ previous) {
9276                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9277                                            }
9278                                            else {
9279                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9280                                            }
9281                                    }
9282                                    else {
9283                                            if (orderByComparator.isAscending() ^ previous) {
9284                                                    query.append(ORDER_BY_ASC);
9285                                            }
9286                                            else {
9287                                                    query.append(ORDER_BY_DESC);
9288                                            }
9289                                    }
9290                            }
9291                    }
9292    
9293                    else {
9294                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9295                    }
9296    
9297                    String sql = query.toString();
9298    
9299                    Query q = session.createQuery(sql);
9300    
9301                    q.setFirstResult(0);
9302                    q.setMaxResults(2);
9303    
9304                    QueryPos qPos = QueryPos.getInstance(q);
9305    
9306                    qPos.add(threadId);
9307    
9308                    qPos.add(answer);
9309    
9310                    if (orderByComparator != null) {
9311                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9312    
9313                            for (Object value : values) {
9314                                    qPos.add(value);
9315                            }
9316                    }
9317    
9318                    List<MBMessage> list = q.list();
9319    
9320                    if (list.size() == 2) {
9321                            return list.get(1);
9322                    }
9323                    else {
9324                            return null;
9325                    }
9326            }
9327    
9328            /**
9329             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
9330             *
9331             * @param threadId the thread ID
9332             * @param status the status
9333             * @return the matching message-boards messages
9334             * @throws SystemException if a system exception occurred
9335             */
9336            public List<MBMessage> findByT_S(long threadId, int status)
9337                    throws SystemException {
9338                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
9339                            QueryUtil.ALL_POS, null);
9340            }
9341    
9342            /**
9343             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
9344             *
9345             * <p>
9346             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9347             * </p>
9348             *
9349             * @param threadId the thread ID
9350             * @param status the status
9351             * @param start the lower bound of the range of message-boards messages
9352             * @param end the upper bound of the range of message-boards messages (not inclusive)
9353             * @return the range of matching message-boards messages
9354             * @throws SystemException if a system exception occurred
9355             */
9356            public List<MBMessage> findByT_S(long threadId, int status, int start,
9357                    int end) throws SystemException {
9358                    return findByT_S(threadId, status, start, end, null);
9359            }
9360    
9361            /**
9362             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
9363             *
9364             * <p>
9365             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9366             * </p>
9367             *
9368             * @param threadId the thread ID
9369             * @param status the status
9370             * @param start the lower bound of the range of message-boards messages
9371             * @param end the upper bound of the range of message-boards messages (not inclusive)
9372             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9373             * @return the ordered range of matching message-boards messages
9374             * @throws SystemException if a system exception occurred
9375             */
9376            public List<MBMessage> findByT_S(long threadId, int status, int start,
9377                    int end, OrderByComparator orderByComparator) throws SystemException {
9378                    FinderPath finderPath = null;
9379                    Object[] finderArgs = null;
9380    
9381                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9382                                    (orderByComparator == null)) {
9383                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
9384                            finderArgs = new Object[] { threadId, status };
9385                    }
9386                    else {
9387                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
9388                            finderArgs = new Object[] {
9389                                            threadId, status,
9390                                            
9391                                            start, end, orderByComparator
9392                                    };
9393                    }
9394    
9395                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9396                                    finderArgs, this);
9397    
9398                    if ((list != null) && !list.isEmpty()) {
9399                            for (MBMessage mbMessage : list) {
9400                                    if ((threadId != mbMessage.getThreadId()) ||
9401                                                    (status != mbMessage.getStatus())) {
9402                                            list = null;
9403    
9404                                            break;
9405                                    }
9406                            }
9407                    }
9408    
9409                    if (list == null) {
9410                            StringBundler query = null;
9411    
9412                            if (orderByComparator != null) {
9413                                    query = new StringBundler(4 +
9414                                                    (orderByComparator.getOrderByFields().length * 3));
9415                            }
9416                            else {
9417                                    query = new StringBundler(4);
9418                            }
9419    
9420                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9421    
9422                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
9423    
9424                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
9425    
9426                            if (orderByComparator != null) {
9427                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9428                                            orderByComparator);
9429                            }
9430    
9431                            else {
9432                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9433                            }
9434    
9435                            String sql = query.toString();
9436    
9437                            Session session = null;
9438    
9439                            try {
9440                                    session = openSession();
9441    
9442                                    Query q = session.createQuery(sql);
9443    
9444                                    QueryPos qPos = QueryPos.getInstance(q);
9445    
9446                                    qPos.add(threadId);
9447    
9448                                    qPos.add(status);
9449    
9450                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
9451                                                    end);
9452                            }
9453                            catch (Exception e) {
9454                                    throw processException(e);
9455                            }
9456                            finally {
9457                                    if (list == null) {
9458                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
9459                                    }
9460                                    else {
9461                                            cacheResult(list);
9462    
9463                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
9464                                    }
9465    
9466                                    closeSession(session);
9467                            }
9468                    }
9469    
9470                    return list;
9471            }
9472    
9473            /**
9474             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9475             *
9476             * @param threadId the thread ID
9477             * @param status the status
9478             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9479             * @return the first matching message-boards message
9480             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9481             * @throws SystemException if a system exception occurred
9482             */
9483            public MBMessage findByT_S_First(long threadId, int status,
9484                    OrderByComparator orderByComparator)
9485                    throws NoSuchMessageException, SystemException {
9486                    MBMessage mbMessage = fetchByT_S_First(threadId, status,
9487                                    orderByComparator);
9488    
9489                    if (mbMessage != null) {
9490                            return mbMessage;
9491                    }
9492    
9493                    StringBundler msg = new StringBundler(6);
9494    
9495                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9496    
9497                    msg.append("threadId=");
9498                    msg.append(threadId);
9499    
9500                    msg.append(", status=");
9501                    msg.append(status);
9502    
9503                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9504    
9505                    throw new NoSuchMessageException(msg.toString());
9506            }
9507    
9508            /**
9509             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9510             *
9511             * @param threadId the thread ID
9512             * @param status the status
9513             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9514             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9515             * @throws SystemException if a system exception occurred
9516             */
9517            public MBMessage fetchByT_S_First(long threadId, int status,
9518                    OrderByComparator orderByComparator) throws SystemException {
9519                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
9520                                    orderByComparator);
9521    
9522                    if (!list.isEmpty()) {
9523                            return list.get(0);
9524                    }
9525    
9526                    return null;
9527            }
9528    
9529            /**
9530             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9531             *
9532             * @param threadId the thread ID
9533             * @param status the status
9534             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9535             * @return the last matching message-boards message
9536             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9537             * @throws SystemException if a system exception occurred
9538             */
9539            public MBMessage findByT_S_Last(long threadId, int status,
9540                    OrderByComparator orderByComparator)
9541                    throws NoSuchMessageException, SystemException {
9542                    MBMessage mbMessage = fetchByT_S_Last(threadId, status,
9543                                    orderByComparator);
9544    
9545                    if (mbMessage != null) {
9546                            return mbMessage;
9547                    }
9548    
9549                    StringBundler msg = new StringBundler(6);
9550    
9551                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9552    
9553                    msg.append("threadId=");
9554                    msg.append(threadId);
9555    
9556                    msg.append(", status=");
9557                    msg.append(status);
9558    
9559                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9560    
9561                    throw new NoSuchMessageException(msg.toString());
9562            }
9563    
9564            /**
9565             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9566             *
9567             * @param threadId the thread ID
9568             * @param status the status
9569             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9570             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9571             * @throws SystemException if a system exception occurred
9572             */
9573            public MBMessage fetchByT_S_Last(long threadId, int status,
9574                    OrderByComparator orderByComparator) throws SystemException {
9575                    int count = countByT_S(threadId, status);
9576    
9577                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
9578                                    orderByComparator);
9579    
9580                    if (!list.isEmpty()) {
9581                            return list.get(0);
9582                    }
9583    
9584                    return null;
9585            }
9586    
9587            /**
9588             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9589             *
9590             * @param messageId the primary key of the current message-boards message
9591             * @param threadId the thread ID
9592             * @param status the status
9593             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9594             * @return the previous, current, and next message-boards message
9595             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9596             * @throws SystemException if a system exception occurred
9597             */
9598            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
9599                    int status, OrderByComparator orderByComparator)
9600                    throws NoSuchMessageException, SystemException {
9601                    MBMessage mbMessage = findByPrimaryKey(messageId);
9602    
9603                    Session session = null;
9604    
9605                    try {
9606                            session = openSession();
9607    
9608                            MBMessage[] array = new MBMessageImpl[3];
9609    
9610                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9611                                            status, orderByComparator, true);
9612    
9613                            array[1] = mbMessage;
9614    
9615                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9616                                            status, orderByComparator, false);
9617    
9618                            return array;
9619                    }
9620                    catch (Exception e) {
9621                            throw processException(e);
9622                    }
9623                    finally {
9624                            closeSession(session);
9625                    }
9626            }
9627    
9628            protected MBMessage getByT_S_PrevAndNext(Session session,
9629                    MBMessage mbMessage, long threadId, int status,
9630                    OrderByComparator orderByComparator, boolean previous) {
9631                    StringBundler query = null;
9632    
9633                    if (orderByComparator != null) {
9634                            query = new StringBundler(6 +
9635                                            (orderByComparator.getOrderByFields().length * 6));
9636                    }
9637                    else {
9638                            query = new StringBundler(3);
9639                    }
9640    
9641                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9642    
9643                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
9644    
9645                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
9646    
9647                    if (orderByComparator != null) {
9648                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9649    
9650                            if (orderByConditionFields.length > 0) {
9651                                    query.append(WHERE_AND);
9652                            }
9653    
9654                            for (int i = 0; i < orderByConditionFields.length; i++) {
9655                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9656                                    query.append(orderByConditionFields[i]);
9657    
9658                                    if ((i + 1) < orderByConditionFields.length) {
9659                                            if (orderByComparator.isAscending() ^ previous) {
9660                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9661                                            }
9662                                            else {
9663                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9664                                            }
9665                                    }
9666                                    else {
9667                                            if (orderByComparator.isAscending() ^ previous) {
9668                                                    query.append(WHERE_GREATER_THAN);
9669                                            }
9670                                            else {
9671                                                    query.append(WHERE_LESSER_THAN);
9672                                            }
9673                                    }
9674                            }
9675    
9676                            query.append(ORDER_BY_CLAUSE);
9677    
9678                            String[] orderByFields = orderByComparator.getOrderByFields();
9679    
9680                            for (int i = 0; i < orderByFields.length; i++) {
9681                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9682                                    query.append(orderByFields[i]);
9683    
9684                                    if ((i + 1) < orderByFields.length) {
9685                                            if (orderByComparator.isAscending() ^ previous) {
9686                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9687                                            }
9688                                            else {
9689                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9690                                            }
9691                                    }
9692                                    else {
9693                                            if (orderByComparator.isAscending() ^ previous) {
9694                                                    query.append(ORDER_BY_ASC);
9695                                            }
9696                                            else {
9697                                                    query.append(ORDER_BY_DESC);
9698                                            }
9699                                    }
9700                            }
9701                    }
9702    
9703                    else {
9704                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9705                    }
9706    
9707                    String sql = query.toString();
9708    
9709                    Query q = session.createQuery(sql);
9710    
9711                    q.setFirstResult(0);
9712                    q.setMaxResults(2);
9713    
9714                    QueryPos qPos = QueryPos.getInstance(q);
9715    
9716                    qPos.add(threadId);
9717    
9718                    qPos.add(status);
9719    
9720                    if (orderByComparator != null) {
9721                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9722    
9723                            for (Object value : values) {
9724                                    qPos.add(value);
9725                            }
9726                    }
9727    
9728                    List<MBMessage> list = q.list();
9729    
9730                    if (list.size() == 2) {
9731                            return list.get(1);
9732                    }
9733                    else {
9734                            return null;
9735                    }
9736            }
9737    
9738            /**
9739             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
9740             *
9741             * @param threadId the thread ID
9742             * @param status the status
9743             * @return the matching message-boards messages
9744             * @throws SystemException if a system exception occurred
9745             */
9746            public List<MBMessage> findByTR_S(long threadId, int status)
9747                    throws SystemException {
9748                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
9749                            QueryUtil.ALL_POS, null);
9750            }
9751    
9752            /**
9753             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
9754             *
9755             * <p>
9756             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9757             * </p>
9758             *
9759             * @param threadId the thread ID
9760             * @param status the status
9761             * @param start the lower bound of the range of message-boards messages
9762             * @param end the upper bound of the range of message-boards messages (not inclusive)
9763             * @return the range of matching message-boards messages
9764             * @throws SystemException if a system exception occurred
9765             */
9766            public List<MBMessage> findByTR_S(long threadId, int status, int start,
9767                    int end) throws SystemException {
9768                    return findByTR_S(threadId, status, start, end, null);
9769            }
9770    
9771            /**
9772             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
9773             *
9774             * <p>
9775             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
9776             * </p>
9777             *
9778             * @param threadId the thread ID
9779             * @param status the status
9780             * @param start the lower bound of the range of message-boards messages
9781             * @param end the upper bound of the range of message-boards messages (not inclusive)
9782             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9783             * @return the ordered range of matching message-boards messages
9784             * @throws SystemException if a system exception occurred
9785             */
9786            public List<MBMessage> findByTR_S(long threadId, int status, int start,
9787                    int end, OrderByComparator orderByComparator) throws SystemException {
9788                    FinderPath finderPath = null;
9789                    Object[] finderArgs = null;
9790    
9791                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9792                                    (orderByComparator == null)) {
9793                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
9794                            finderArgs = new Object[] { threadId, status };
9795                    }
9796                    else {
9797                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
9798                            finderArgs = new Object[] {
9799                                            threadId, status,
9800                                            
9801                                            start, end, orderByComparator
9802                                    };
9803                    }
9804    
9805                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9806                                    finderArgs, this);
9807    
9808                    if ((list != null) && !list.isEmpty()) {
9809                            for (MBMessage mbMessage : list) {
9810                                    if ((threadId != mbMessage.getThreadId()) ||
9811                                                    (status != mbMessage.getStatus())) {
9812                                            list = null;
9813    
9814                                            break;
9815                                    }
9816                            }
9817                    }
9818    
9819                    if (list == null) {
9820                            StringBundler query = null;
9821    
9822                            if (orderByComparator != null) {
9823                                    query = new StringBundler(4 +
9824                                                    (orderByComparator.getOrderByFields().length * 3));
9825                            }
9826                            else {
9827                                    query = new StringBundler(4);
9828                            }
9829    
9830                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9831    
9832                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
9833    
9834                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
9835    
9836                            if (orderByComparator != null) {
9837                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9838                                            orderByComparator);
9839                            }
9840    
9841                            else {
9842                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9843                            }
9844    
9845                            String sql = query.toString();
9846    
9847                            Session session = null;
9848    
9849                            try {
9850                                    session = openSession();
9851    
9852                                    Query q = session.createQuery(sql);
9853    
9854                                    QueryPos qPos = QueryPos.getInstance(q);
9855    
9856                                    qPos.add(threadId);
9857    
9858                                    qPos.add(status);
9859    
9860                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
9861                                                    end);
9862                            }
9863                            catch (Exception e) {
9864                                    throw processException(e);
9865                            }
9866                            finally {
9867                                    if (list == null) {
9868                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
9869                                    }
9870                                    else {
9871                                            cacheResult(list);
9872    
9873                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
9874                                    }
9875    
9876                                    closeSession(session);
9877                            }
9878                    }
9879    
9880                    return list;
9881            }
9882    
9883            /**
9884             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9885             *
9886             * @param threadId the thread ID
9887             * @param status the status
9888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9889             * @return the first matching message-boards message
9890             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9891             * @throws SystemException if a system exception occurred
9892             */
9893            public MBMessage findByTR_S_First(long threadId, int status,
9894                    OrderByComparator orderByComparator)
9895                    throws NoSuchMessageException, SystemException {
9896                    MBMessage mbMessage = fetchByTR_S_First(threadId, status,
9897                                    orderByComparator);
9898    
9899                    if (mbMessage != null) {
9900                            return mbMessage;
9901                    }
9902    
9903                    StringBundler msg = new StringBundler(6);
9904    
9905                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9906    
9907                    msg.append("threadId=");
9908                    msg.append(threadId);
9909    
9910                    msg.append(", status=");
9911                    msg.append(status);
9912    
9913                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9914    
9915                    throw new NoSuchMessageException(msg.toString());
9916            }
9917    
9918            /**
9919             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9920             *
9921             * @param threadId the thread ID
9922             * @param status the status
9923             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9924             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9925             * @throws SystemException if a system exception occurred
9926             */
9927            public MBMessage fetchByTR_S_First(long threadId, int status,
9928                    OrderByComparator orderByComparator) throws SystemException {
9929                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
9930                                    orderByComparator);
9931    
9932                    if (!list.isEmpty()) {
9933                            return list.get(0);
9934                    }
9935    
9936                    return null;
9937            }
9938    
9939            /**
9940             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9941             *
9942             * @param threadId the thread ID
9943             * @param status the status
9944             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9945             * @return the last matching message-boards message
9946             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9947             * @throws SystemException if a system exception occurred
9948             */
9949            public MBMessage findByTR_S_Last(long threadId, int status,
9950                    OrderByComparator orderByComparator)
9951                    throws NoSuchMessageException, SystemException {
9952                    MBMessage mbMessage = fetchByTR_S_Last(threadId, status,
9953                                    orderByComparator);
9954    
9955                    if (mbMessage != null) {
9956                            return mbMessage;
9957                    }
9958    
9959                    StringBundler msg = new StringBundler(6);
9960    
9961                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9962    
9963                    msg.append("threadId=");
9964                    msg.append(threadId);
9965    
9966                    msg.append(", status=");
9967                    msg.append(status);
9968    
9969                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9970    
9971                    throw new NoSuchMessageException(msg.toString());
9972            }
9973    
9974            /**
9975             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9976             *
9977             * @param threadId the thread ID
9978             * @param status the status
9979             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9980             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9981             * @throws SystemException if a system exception occurred
9982             */
9983            public MBMessage fetchByTR_S_Last(long threadId, int status,
9984                    OrderByComparator orderByComparator) throws SystemException {
9985                    int count = countByTR_S(threadId, status);
9986    
9987                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
9988                                    orderByComparator);
9989    
9990                    if (!list.isEmpty()) {
9991                            return list.get(0);
9992                    }
9993    
9994                    return null;
9995            }
9996    
9997            /**
9998             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9999             *
10000             * @param messageId the primary key of the current message-boards message
10001             * @param threadId the thread ID
10002             * @param status the status
10003             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10004             * @return the previous, current, and next message-boards message
10005             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10006             * @throws SystemException if a system exception occurred
10007             */
10008            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
10009                    int status, OrderByComparator orderByComparator)
10010                    throws NoSuchMessageException, SystemException {
10011                    MBMessage mbMessage = findByPrimaryKey(messageId);
10012    
10013                    Session session = null;
10014    
10015                    try {
10016                            session = openSession();
10017    
10018                            MBMessage[] array = new MBMessageImpl[3];
10019    
10020                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10021                                            status, orderByComparator, true);
10022    
10023                            array[1] = mbMessage;
10024    
10025                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10026                                            status, orderByComparator, false);
10027    
10028                            return array;
10029                    }
10030                    catch (Exception e) {
10031                            throw processException(e);
10032                    }
10033                    finally {
10034                            closeSession(session);
10035                    }
10036            }
10037    
10038            protected MBMessage getByTR_S_PrevAndNext(Session session,
10039                    MBMessage mbMessage, long threadId, int status,
10040                    OrderByComparator orderByComparator, boolean previous) {
10041                    StringBundler query = null;
10042    
10043                    if (orderByComparator != null) {
10044                            query = new StringBundler(6 +
10045                                            (orderByComparator.getOrderByFields().length * 6));
10046                    }
10047                    else {
10048                            query = new StringBundler(3);
10049                    }
10050    
10051                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10052    
10053                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10054    
10055                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10056    
10057                    if (orderByComparator != null) {
10058                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10059    
10060                            if (orderByConditionFields.length > 0) {
10061                                    query.append(WHERE_AND);
10062                            }
10063    
10064                            for (int i = 0; i < orderByConditionFields.length; i++) {
10065                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10066                                    query.append(orderByConditionFields[i]);
10067    
10068                                    if ((i + 1) < orderByConditionFields.length) {
10069                                            if (orderByComparator.isAscending() ^ previous) {
10070                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10071                                            }
10072                                            else {
10073                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10074                                            }
10075                                    }
10076                                    else {
10077                                            if (orderByComparator.isAscending() ^ previous) {
10078                                                    query.append(WHERE_GREATER_THAN);
10079                                            }
10080                                            else {
10081                                                    query.append(WHERE_LESSER_THAN);
10082                                            }
10083                                    }
10084                            }
10085    
10086                            query.append(ORDER_BY_CLAUSE);
10087    
10088                            String[] orderByFields = orderByComparator.getOrderByFields();
10089    
10090                            for (int i = 0; i < orderByFields.length; i++) {
10091                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10092                                    query.append(orderByFields[i]);
10093    
10094                                    if ((i + 1) < orderByFields.length) {
10095                                            if (orderByComparator.isAscending() ^ previous) {
10096                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10097                                            }
10098                                            else {
10099                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10100                                            }
10101                                    }
10102                                    else {
10103                                            if (orderByComparator.isAscending() ^ previous) {
10104                                                    query.append(ORDER_BY_ASC);
10105                                            }
10106                                            else {
10107                                                    query.append(ORDER_BY_DESC);
10108                                            }
10109                                    }
10110                            }
10111                    }
10112    
10113                    else {
10114                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10115                    }
10116    
10117                    String sql = query.toString();
10118    
10119                    Query q = session.createQuery(sql);
10120    
10121                    q.setFirstResult(0);
10122                    q.setMaxResults(2);
10123    
10124                    QueryPos qPos = QueryPos.getInstance(q);
10125    
10126                    qPos.add(threadId);
10127    
10128                    qPos.add(status);
10129    
10130                    if (orderByComparator != null) {
10131                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10132    
10133                            for (Object value : values) {
10134                                    qPos.add(value);
10135                            }
10136                    }
10137    
10138                    List<MBMessage> list = q.list();
10139    
10140                    if (list.size() == 2) {
10141                            return list.get(1);
10142                    }
10143                    else {
10144                            return null;
10145                    }
10146            }
10147    
10148            /**
10149             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10150             *
10151             * @param groupId the group ID
10152             * @param userId the user ID
10153             * @param status the status
10154             * @return the matching message-boards messages
10155             * @throws SystemException if a system exception occurred
10156             */
10157            public List<MBMessage> findByG_U_S(long groupId, long userId, int status)
10158                    throws SystemException {
10159                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
10160                            QueryUtil.ALL_POS, null);
10161            }
10162    
10163            /**
10164             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10165             *
10166             * <p>
10167             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10168             * </p>
10169             *
10170             * @param groupId the group ID
10171             * @param userId the user ID
10172             * @param status the status
10173             * @param start the lower bound of the range of message-boards messages
10174             * @param end the upper bound of the range of message-boards messages (not inclusive)
10175             * @return the range of matching message-boards messages
10176             * @throws SystemException if a system exception occurred
10177             */
10178            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
10179                    int start, int end) throws SystemException {
10180                    return findByG_U_S(groupId, userId, status, start, end, null);
10181            }
10182    
10183            /**
10184             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#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 userId the user ID
10192             * @param status the status
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             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10196             * @return the ordered range of matching message-boards messages
10197             * @throws SystemException if a system exception occurred
10198             */
10199            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
10200                    int start, int end, OrderByComparator orderByComparator)
10201                    throws SystemException {
10202                    FinderPath finderPath = null;
10203                    Object[] finderArgs = null;
10204    
10205                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10206                                    (orderByComparator == null)) {
10207                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
10208                            finderArgs = new Object[] { groupId, userId, status };
10209                    }
10210                    else {
10211                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
10212                            finderArgs = new Object[] {
10213                                            groupId, userId, status,
10214                                            
10215                                            start, end, orderByComparator
10216                                    };
10217                    }
10218    
10219                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10220                                    finderArgs, this);
10221    
10222                    if ((list != null) && !list.isEmpty()) {
10223                            for (MBMessage mbMessage : list) {
10224                                    if ((groupId != mbMessage.getGroupId()) ||
10225                                                    (userId != mbMessage.getUserId()) ||
10226                                                    (status != mbMessage.getStatus())) {
10227                                            list = null;
10228    
10229                                            break;
10230                                    }
10231                            }
10232                    }
10233    
10234                    if (list == null) {
10235                            StringBundler query = null;
10236    
10237                            if (orderByComparator != null) {
10238                                    query = new StringBundler(5 +
10239                                                    (orderByComparator.getOrderByFields().length * 3));
10240                            }
10241                            else {
10242                                    query = new StringBundler(5);
10243                            }
10244    
10245                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10246    
10247                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10248    
10249                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10250    
10251                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10252    
10253                            if (orderByComparator != null) {
10254                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10255                                            orderByComparator);
10256                            }
10257    
10258                            else {
10259                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10260                            }
10261    
10262                            String sql = query.toString();
10263    
10264                            Session session = null;
10265    
10266                            try {
10267                                    session = openSession();
10268    
10269                                    Query q = session.createQuery(sql);
10270    
10271                                    QueryPos qPos = QueryPos.getInstance(q);
10272    
10273                                    qPos.add(groupId);
10274    
10275                                    qPos.add(userId);
10276    
10277                                    qPos.add(status);
10278    
10279                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
10280                                                    end);
10281                            }
10282                            catch (Exception e) {
10283                                    throw processException(e);
10284                            }
10285                            finally {
10286                                    if (list == null) {
10287                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
10288                                    }
10289                                    else {
10290                                            cacheResult(list);
10291    
10292                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
10293                                    }
10294    
10295                                    closeSession(session);
10296                            }
10297                    }
10298    
10299                    return list;
10300            }
10301    
10302            /**
10303             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10304             *
10305             * @param groupId the group ID
10306             * @param userId the user ID
10307             * @param status the status
10308             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10309             * @return the first matching message-boards message
10310             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10311             * @throws SystemException if a system exception occurred
10312             */
10313            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
10314                    OrderByComparator orderByComparator)
10315                    throws NoSuchMessageException, SystemException {
10316                    MBMessage mbMessage = fetchByG_U_S_First(groupId, userId, status,
10317                                    orderByComparator);
10318    
10319                    if (mbMessage != null) {
10320                            return mbMessage;
10321                    }
10322    
10323                    StringBundler msg = new StringBundler(8);
10324    
10325                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10326    
10327                    msg.append("groupId=");
10328                    msg.append(groupId);
10329    
10330                    msg.append(", userId=");
10331                    msg.append(userId);
10332    
10333                    msg.append(", status=");
10334                    msg.append(status);
10335    
10336                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10337    
10338                    throw new NoSuchMessageException(msg.toString());
10339            }
10340    
10341            /**
10342             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10343             *
10344             * @param groupId the group ID
10345             * @param userId the user ID
10346             * @param status the status
10347             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10348             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10349             * @throws SystemException if a system exception occurred
10350             */
10351            public MBMessage fetchByG_U_S_First(long groupId, long userId, int status,
10352                    OrderByComparator orderByComparator) throws SystemException {
10353                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
10354                                    orderByComparator);
10355    
10356                    if (!list.isEmpty()) {
10357                            return list.get(0);
10358                    }
10359    
10360                    return null;
10361            }
10362    
10363            /**
10364             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10365             *
10366             * @param groupId the group ID
10367             * @param userId the user ID
10368             * @param status the status
10369             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10370             * @return the last matching message-boards message
10371             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10372             * @throws SystemException if a system exception occurred
10373             */
10374            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
10375                    OrderByComparator orderByComparator)
10376                    throws NoSuchMessageException, SystemException {
10377                    MBMessage mbMessage = fetchByG_U_S_Last(groupId, userId, status,
10378                                    orderByComparator);
10379    
10380                    if (mbMessage != null) {
10381                            return mbMessage;
10382                    }
10383    
10384                    StringBundler msg = new StringBundler(8);
10385    
10386                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10387    
10388                    msg.append("groupId=");
10389                    msg.append(groupId);
10390    
10391                    msg.append(", userId=");
10392                    msg.append(userId);
10393    
10394                    msg.append(", status=");
10395                    msg.append(status);
10396    
10397                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10398    
10399                    throw new NoSuchMessageException(msg.toString());
10400            }
10401    
10402            /**
10403             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10404             *
10405             * @param groupId the group ID
10406             * @param userId the user ID
10407             * @param status the status
10408             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10409             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10410             * @throws SystemException if a system exception occurred
10411             */
10412            public MBMessage fetchByG_U_S_Last(long groupId, long userId, int status,
10413                    OrderByComparator orderByComparator) throws SystemException {
10414                    int count = countByG_U_S(groupId, userId, status);
10415    
10416                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
10417                                    count, orderByComparator);
10418    
10419                    if (!list.isEmpty()) {
10420                            return list.get(0);
10421                    }
10422    
10423                    return null;
10424            }
10425    
10426            /**
10427             * 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;.
10428             *
10429             * @param messageId the primary key of the current message-boards message
10430             * @param groupId the group ID
10431             * @param userId the user ID
10432             * @param status the status
10433             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10434             * @return the previous, current, and next message-boards message
10435             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10436             * @throws SystemException if a system exception occurred
10437             */
10438            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
10439                    long userId, int status, OrderByComparator orderByComparator)
10440                    throws NoSuchMessageException, SystemException {
10441                    MBMessage mbMessage = findByPrimaryKey(messageId);
10442    
10443                    Session session = null;
10444    
10445                    try {
10446                            session = openSession();
10447    
10448                            MBMessage[] array = new MBMessageImpl[3];
10449    
10450                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
10451                                            userId, status, orderByComparator, true);
10452    
10453                            array[1] = mbMessage;
10454    
10455                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
10456                                            userId, status, orderByComparator, false);
10457    
10458                            return array;
10459                    }
10460                    catch (Exception e) {
10461                            throw processException(e);
10462                    }
10463                    finally {
10464                            closeSession(session);
10465                    }
10466            }
10467    
10468            protected MBMessage getByG_U_S_PrevAndNext(Session session,
10469                    MBMessage mbMessage, long groupId, long userId, int status,
10470                    OrderByComparator orderByComparator, boolean previous) {
10471                    StringBundler query = null;
10472    
10473                    if (orderByComparator != null) {
10474                            query = new StringBundler(6 +
10475                                            (orderByComparator.getOrderByFields().length * 6));
10476                    }
10477                    else {
10478                            query = new StringBundler(3);
10479                    }
10480    
10481                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10482    
10483                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10484    
10485                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10486    
10487                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10488    
10489                    if (orderByComparator != null) {
10490                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10491    
10492                            if (orderByConditionFields.length > 0) {
10493                                    query.append(WHERE_AND);
10494                            }
10495    
10496                            for (int i = 0; i < orderByConditionFields.length; i++) {
10497                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10498                                    query.append(orderByConditionFields[i]);
10499    
10500                                    if ((i + 1) < orderByConditionFields.length) {
10501                                            if (orderByComparator.isAscending() ^ previous) {
10502                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10503                                            }
10504                                            else {
10505                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10506                                            }
10507                                    }
10508                                    else {
10509                                            if (orderByComparator.isAscending() ^ previous) {
10510                                                    query.append(WHERE_GREATER_THAN);
10511                                            }
10512                                            else {
10513                                                    query.append(WHERE_LESSER_THAN);
10514                                            }
10515                                    }
10516                            }
10517    
10518                            query.append(ORDER_BY_CLAUSE);
10519    
10520                            String[] orderByFields = orderByComparator.getOrderByFields();
10521    
10522                            for (int i = 0; i < orderByFields.length; i++) {
10523                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10524                                    query.append(orderByFields[i]);
10525    
10526                                    if ((i + 1) < orderByFields.length) {
10527                                            if (orderByComparator.isAscending() ^ previous) {
10528                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10529                                            }
10530                                            else {
10531                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10532                                            }
10533                                    }
10534                                    else {
10535                                            if (orderByComparator.isAscending() ^ previous) {
10536                                                    query.append(ORDER_BY_ASC);
10537                                            }
10538                                            else {
10539                                                    query.append(ORDER_BY_DESC);
10540                                            }
10541                                    }
10542                            }
10543                    }
10544    
10545                    else {
10546                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10547                    }
10548    
10549                    String sql = query.toString();
10550    
10551                    Query q = session.createQuery(sql);
10552    
10553                    q.setFirstResult(0);
10554                    q.setMaxResults(2);
10555    
10556                    QueryPos qPos = QueryPos.getInstance(q);
10557    
10558                    qPos.add(groupId);
10559    
10560                    qPos.add(userId);
10561    
10562                    qPos.add(status);
10563    
10564                    if (orderByComparator != null) {
10565                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10566    
10567                            for (Object value : values) {
10568                                    qPos.add(value);
10569                            }
10570                    }
10571    
10572                    List<MBMessage> list = q.list();
10573    
10574                    if (list.size() == 2) {
10575                            return list.get(1);
10576                    }
10577                    else {
10578                            return null;
10579                    }
10580            }
10581    
10582            /**
10583             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
10584             *
10585             * @param groupId the group ID
10586             * @param userId the user ID
10587             * @param status the status
10588             * @return the matching message-boards messages that the user has permission to view
10589             * @throws SystemException if a system exception occurred
10590             */
10591            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
10592                    int status) throws SystemException {
10593                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
10594                            QueryUtil.ALL_POS, null);
10595            }
10596    
10597            /**
10598             * 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;.
10599             *
10600             * <p>
10601             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10602             * </p>
10603             *
10604             * @param groupId the group ID
10605             * @param userId the user ID
10606             * @param status the status
10607             * @param start the lower bound of the range of message-boards messages
10608             * @param end the upper bound of the range of message-boards messages (not inclusive)
10609             * @return the range of matching message-boards messages that the user has permission to view
10610             * @throws SystemException if a system exception occurred
10611             */
10612            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
10613                    int status, int start, int end) throws SystemException {
10614                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
10615            }
10616    
10617            /**
10618             * 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;.
10619             *
10620             * <p>
10621             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10622             * </p>
10623             *
10624             * @param groupId the group ID
10625             * @param userId the user ID
10626             * @param status the status
10627             * @param start the lower bound of the range of message-boards messages
10628             * @param end the upper bound of the range of message-boards messages (not inclusive)
10629             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10630             * @return the ordered range of matching message-boards messages that the user has permission to view
10631             * @throws SystemException if a system exception occurred
10632             */
10633            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
10634                    int status, int start, int end, OrderByComparator orderByComparator)
10635                    throws SystemException {
10636                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10637                            return findByG_U_S(groupId, userId, status, start, end,
10638                                    orderByComparator);
10639                    }
10640    
10641                    StringBundler query = null;
10642    
10643                    if (orderByComparator != null) {
10644                            query = new StringBundler(5 +
10645                                            (orderByComparator.getOrderByFields().length * 3));
10646                    }
10647                    else {
10648                            query = new StringBundler(5);
10649                    }
10650    
10651                    if (getDB().isSupportsInlineDistinct()) {
10652                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
10653                    }
10654                    else {
10655                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
10656                    }
10657    
10658                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10659    
10660                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10661    
10662                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10663    
10664                    if (!getDB().isSupportsInlineDistinct()) {
10665                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
10666                    }
10667    
10668                    if (orderByComparator != null) {
10669                            if (getDB().isSupportsInlineDistinct()) {
10670                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10671                                            orderByComparator);
10672                            }
10673                            else {
10674                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10675                                            orderByComparator);
10676                            }
10677                    }
10678    
10679                    else {
10680                            if (getDB().isSupportsInlineDistinct()) {
10681                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10682                            }
10683                            else {
10684                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
10685                            }
10686                    }
10687    
10688                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10689                                    MBMessage.class.getName(),
10690                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10691    
10692                    Session session = null;
10693    
10694                    try {
10695                            session = openSession();
10696    
10697                            SQLQuery q = session.createSQLQuery(sql);
10698    
10699                            if (getDB().isSupportsInlineDistinct()) {
10700                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
10701                            }
10702                            else {
10703                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
10704                            }
10705    
10706                            QueryPos qPos = QueryPos.getInstance(q);
10707    
10708                            qPos.add(groupId);
10709    
10710                            qPos.add(userId);
10711    
10712                            qPos.add(status);
10713    
10714                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
10715                    }
10716                    catch (Exception e) {
10717                            throw processException(e);
10718                    }
10719                    finally {
10720                            closeSession(session);
10721                    }
10722            }
10723    
10724            /**
10725             * 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;.
10726             *
10727             * @param messageId the primary key of the current message-boards message
10728             * @param groupId the group ID
10729             * @param userId the user ID
10730             * @param status the status
10731             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10732             * @return the previous, current, and next message-boards message
10733             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10734             * @throws SystemException if a system exception occurred
10735             */
10736            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
10737                    long groupId, long userId, int status,
10738                    OrderByComparator orderByComparator)
10739                    throws NoSuchMessageException, SystemException {
10740                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10741                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
10742                                    orderByComparator);
10743                    }
10744    
10745                    MBMessage mbMessage = findByPrimaryKey(messageId);
10746    
10747                    Session session = null;
10748    
10749                    try {
10750                            session = openSession();
10751    
10752                            MBMessage[] array = new MBMessageImpl[3];
10753    
10754                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
10755                                            groupId, userId, status, orderByComparator, true);
10756    
10757                            array[1] = mbMessage;
10758    
10759                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
10760                                            groupId, userId, status, orderByComparator, false);
10761    
10762                            return array;
10763                    }
10764                    catch (Exception e) {
10765                            throw processException(e);
10766                    }
10767                    finally {
10768                            closeSession(session);
10769                    }
10770            }
10771    
10772            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
10773                    MBMessage mbMessage, long groupId, long userId, int status,
10774                    OrderByComparator orderByComparator, boolean previous) {
10775                    StringBundler query = null;
10776    
10777                    if (orderByComparator != null) {
10778                            query = new StringBundler(6 +
10779                                            (orderByComparator.getOrderByFields().length * 6));
10780                    }
10781                    else {
10782                            query = new StringBundler(3);
10783                    }
10784    
10785                    if (getDB().isSupportsInlineDistinct()) {
10786                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
10787                    }
10788                    else {
10789                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
10790                    }
10791    
10792                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10793    
10794                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10795    
10796                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10797    
10798                    if (!getDB().isSupportsInlineDistinct()) {
10799                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
10800                    }
10801    
10802                    if (orderByComparator != null) {
10803                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10804    
10805                            if (orderByConditionFields.length > 0) {
10806                                    query.append(WHERE_AND);
10807                            }
10808    
10809                            for (int i = 0; i < orderByConditionFields.length; i++) {
10810                                    if (getDB().isSupportsInlineDistinct()) {
10811                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10812                                    }
10813                                    else {
10814                                            query.append(_ORDER_BY_ENTITY_TABLE);
10815                                    }
10816    
10817                                    query.append(orderByConditionFields[i]);
10818    
10819                                    if ((i + 1) < orderByConditionFields.length) {
10820                                            if (orderByComparator.isAscending() ^ previous) {
10821                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10822                                            }
10823                                            else {
10824                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10825                                            }
10826                                    }
10827                                    else {
10828                                            if (orderByComparator.isAscending() ^ previous) {
10829                                                    query.append(WHERE_GREATER_THAN);
10830                                            }
10831                                            else {
10832                                                    query.append(WHERE_LESSER_THAN);
10833                                            }
10834                                    }
10835                            }
10836    
10837                            query.append(ORDER_BY_CLAUSE);
10838    
10839                            String[] orderByFields = orderByComparator.getOrderByFields();
10840    
10841                            for (int i = 0; i < orderByFields.length; i++) {
10842                                    if (getDB().isSupportsInlineDistinct()) {
10843                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10844                                    }
10845                                    else {
10846                                            query.append(_ORDER_BY_ENTITY_TABLE);
10847                                    }
10848    
10849                                    query.append(orderByFields[i]);
10850    
10851                                    if ((i + 1) < orderByFields.length) {
10852                                            if (orderByComparator.isAscending() ^ previous) {
10853                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10854                                            }
10855                                            else {
10856                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10857                                            }
10858                                    }
10859                                    else {
10860                                            if (orderByComparator.isAscending() ^ previous) {
10861                                                    query.append(ORDER_BY_ASC);
10862                                            }
10863                                            else {
10864                                                    query.append(ORDER_BY_DESC);
10865                                            }
10866                                    }
10867                            }
10868                    }
10869    
10870                    else {
10871                            if (getDB().isSupportsInlineDistinct()) {
10872                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10873                            }
10874                            else {
10875                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
10876                            }
10877                    }
10878    
10879                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10880                                    MBMessage.class.getName(),
10881                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10882    
10883                    SQLQuery q = session.createSQLQuery(sql);
10884    
10885                    q.setFirstResult(0);
10886                    q.setMaxResults(2);
10887    
10888                    if (getDB().isSupportsInlineDistinct()) {
10889                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
10890                    }
10891                    else {
10892                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
10893                    }
10894    
10895                    QueryPos qPos = QueryPos.getInstance(q);
10896    
10897                    qPos.add(groupId);
10898    
10899                    qPos.add(userId);
10900    
10901                    qPos.add(status);
10902    
10903                    if (orderByComparator != null) {
10904                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10905    
10906                            for (Object value : values) {
10907                                    qPos.add(value);
10908                            }
10909                    }
10910    
10911                    List<MBMessage> list = q.list();
10912    
10913                    if (list.size() == 2) {
10914                            return list.get(1);
10915                    }
10916                    else {
10917                            return null;
10918                    }
10919            }
10920    
10921            /**
10922             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10923             *
10924             * @param groupId the group ID
10925             * @param categoryId the category ID
10926             * @param threadId the thread ID
10927             * @return the matching message-boards messages
10928             * @throws SystemException if a system exception occurred
10929             */
10930            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
10931                    long threadId) throws SystemException {
10932                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
10933                            QueryUtil.ALL_POS, null);
10934            }
10935    
10936            /**
10937             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10938             *
10939             * <p>
10940             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10941             * </p>
10942             *
10943             * @param groupId the group ID
10944             * @param categoryId the category ID
10945             * @param threadId the thread ID
10946             * @param start the lower bound of the range of message-boards messages
10947             * @param end the upper bound of the range of message-boards messages (not inclusive)
10948             * @return the range of matching message-boards messages
10949             * @throws SystemException if a system exception occurred
10950             */
10951            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
10952                    long threadId, int start, int end) throws SystemException {
10953                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
10954            }
10955    
10956            /**
10957             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
10958             *
10959             * <p>
10960             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
10961             * </p>
10962             *
10963             * @param groupId the group ID
10964             * @param categoryId the category ID
10965             * @param threadId the thread ID
10966             * @param start the lower bound of the range of message-boards messages
10967             * @param end the upper bound of the range of message-boards messages (not inclusive)
10968             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10969             * @return the ordered range of matching message-boards messages
10970             * @throws SystemException if a system exception occurred
10971             */
10972            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
10973                    long threadId, int start, int end, OrderByComparator orderByComparator)
10974                    throws SystemException {
10975                    FinderPath finderPath = null;
10976                    Object[] finderArgs = null;
10977    
10978                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10979                                    (orderByComparator == null)) {
10980                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
10981                            finderArgs = new Object[] { groupId, categoryId, threadId };
10982                    }
10983                    else {
10984                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
10985                            finderArgs = new Object[] {
10986                                            groupId, categoryId, threadId,
10987                                            
10988                                            start, end, orderByComparator
10989                                    };
10990                    }
10991    
10992                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10993                                    finderArgs, this);
10994    
10995                    if ((list != null) && !list.isEmpty()) {
10996                            for (MBMessage mbMessage : list) {
10997                                    if ((groupId != mbMessage.getGroupId()) ||
10998                                                    (categoryId != mbMessage.getCategoryId()) ||
10999                                                    (threadId != mbMessage.getThreadId())) {
11000                                            list = null;
11001    
11002                                            break;
11003                                    }
11004                            }
11005                    }
11006    
11007                    if (list == null) {
11008                            StringBundler query = null;
11009    
11010                            if (orderByComparator != null) {
11011                                    query = new StringBundler(5 +
11012                                                    (orderByComparator.getOrderByFields().length * 3));
11013                            }
11014                            else {
11015                                    query = new StringBundler(5);
11016                            }
11017    
11018                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11019    
11020                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
11021    
11022                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
11023    
11024                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
11025    
11026                            if (orderByComparator != null) {
11027                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11028                                            orderByComparator);
11029                            }
11030    
11031                            else {
11032                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11033                            }
11034    
11035                            String sql = query.toString();
11036    
11037                            Session session = null;
11038    
11039                            try {
11040                                    session = openSession();
11041    
11042                                    Query q = session.createQuery(sql);
11043    
11044                                    QueryPos qPos = QueryPos.getInstance(q);
11045    
11046                                    qPos.add(groupId);
11047    
11048                                    qPos.add(categoryId);
11049    
11050                                    qPos.add(threadId);
11051    
11052                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
11053                                                    end);
11054                            }
11055                            catch (Exception e) {
11056                                    throw processException(e);
11057                            }
11058                            finally {
11059                                    if (list == null) {
11060                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
11061                                    }
11062                                    else {
11063                                            cacheResult(list);
11064    
11065                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
11066                                    }
11067    
11068                                    closeSession(session);
11069                            }
11070                    }
11071    
11072                    return list;
11073            }
11074    
11075            /**
11076             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11077             *
11078             * @param groupId the group ID
11079             * @param categoryId the category ID
11080             * @param threadId the thread ID
11081             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11082             * @return the first matching message-boards message
11083             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11084             * @throws SystemException if a system exception occurred
11085             */
11086            public MBMessage findByG_C_T_First(long groupId, long categoryId,
11087                    long threadId, OrderByComparator orderByComparator)
11088                    throws NoSuchMessageException, SystemException {
11089                    MBMessage mbMessage = fetchByG_C_T_First(groupId, categoryId, threadId,
11090                                    orderByComparator);
11091    
11092                    if (mbMessage != null) {
11093                            return mbMessage;
11094                    }
11095    
11096                    StringBundler msg = new StringBundler(8);
11097    
11098                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11099    
11100                    msg.append("groupId=");
11101                    msg.append(groupId);
11102    
11103                    msg.append(", categoryId=");
11104                    msg.append(categoryId);
11105    
11106                    msg.append(", threadId=");
11107                    msg.append(threadId);
11108    
11109                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11110    
11111                    throw new NoSuchMessageException(msg.toString());
11112            }
11113    
11114            /**
11115             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11116             *
11117             * @param groupId the group ID
11118             * @param categoryId the category ID
11119             * @param threadId the thread ID
11120             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11121             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11122             * @throws SystemException if a system exception occurred
11123             */
11124            public MBMessage fetchByG_C_T_First(long groupId, long categoryId,
11125                    long threadId, OrderByComparator orderByComparator)
11126                    throws SystemException {
11127                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
11128                                    orderByComparator);
11129    
11130                    if (!list.isEmpty()) {
11131                            return list.get(0);
11132                    }
11133    
11134                    return null;
11135            }
11136    
11137            /**
11138             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11139             *
11140             * @param groupId the group ID
11141             * @param categoryId the category ID
11142             * @param threadId the thread ID
11143             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11144             * @return the last matching message-boards message
11145             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11146             * @throws SystemException if a system exception occurred
11147             */
11148            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
11149                    long threadId, OrderByComparator orderByComparator)
11150                    throws NoSuchMessageException, SystemException {
11151                    MBMessage mbMessage = fetchByG_C_T_Last(groupId, categoryId, threadId,
11152                                    orderByComparator);
11153    
11154                    if (mbMessage != null) {
11155                            return mbMessage;
11156                    }
11157    
11158                    StringBundler msg = new StringBundler(8);
11159    
11160                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11161    
11162                    msg.append("groupId=");
11163                    msg.append(groupId);
11164    
11165                    msg.append(", categoryId=");
11166                    msg.append(categoryId);
11167    
11168                    msg.append(", threadId=");
11169                    msg.append(threadId);
11170    
11171                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11172    
11173                    throw new NoSuchMessageException(msg.toString());
11174            }
11175    
11176            /**
11177             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11178             *
11179             * @param groupId the group ID
11180             * @param categoryId the category ID
11181             * @param threadId the thread ID
11182             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11183             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11184             * @throws SystemException if a system exception occurred
11185             */
11186            public MBMessage fetchByG_C_T_Last(long groupId, long categoryId,
11187                    long threadId, OrderByComparator orderByComparator)
11188                    throws SystemException {
11189                    int count = countByG_C_T(groupId, categoryId, threadId);
11190    
11191                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
11192                                    count - 1, count, orderByComparator);
11193    
11194                    if (!list.isEmpty()) {
11195                            return list.get(0);
11196                    }
11197    
11198                    return null;
11199            }
11200    
11201            /**
11202             * 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;.
11203             *
11204             * @param messageId the primary key of the current message-boards message
11205             * @param groupId the group ID
11206             * @param categoryId the category ID
11207             * @param threadId the thread ID
11208             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11209             * @return the previous, current, and next message-boards message
11210             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11211             * @throws SystemException if a system exception occurred
11212             */
11213            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
11214                    long categoryId, long threadId, OrderByComparator orderByComparator)
11215                    throws NoSuchMessageException, SystemException {
11216                    MBMessage mbMessage = findByPrimaryKey(messageId);
11217    
11218                    Session session = null;
11219    
11220                    try {
11221                            session = openSession();
11222    
11223                            MBMessage[] array = new MBMessageImpl[3];
11224    
11225                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
11226                                            categoryId, threadId, orderByComparator, true);
11227    
11228                            array[1] = mbMessage;
11229    
11230                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
11231                                            categoryId, threadId, orderByComparator, false);
11232    
11233                            return array;
11234                    }
11235                    catch (Exception e) {
11236                            throw processException(e);
11237                    }
11238                    finally {
11239                            closeSession(session);
11240                    }
11241            }
11242    
11243            protected MBMessage getByG_C_T_PrevAndNext(Session session,
11244                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
11245                    OrderByComparator orderByComparator, boolean previous) {
11246                    StringBundler query = null;
11247    
11248                    if (orderByComparator != null) {
11249                            query = new StringBundler(6 +
11250                                            (orderByComparator.getOrderByFields().length * 6));
11251                    }
11252                    else {
11253                            query = new StringBundler(3);
11254                    }
11255    
11256                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11257    
11258                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
11259    
11260                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
11261    
11262                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
11263    
11264                    if (orderByComparator != null) {
11265                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11266    
11267                            if (orderByConditionFields.length > 0) {
11268                                    query.append(WHERE_AND);
11269                            }
11270    
11271                            for (int i = 0; i < orderByConditionFields.length; i++) {
11272                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11273                                    query.append(orderByConditionFields[i]);
11274    
11275                                    if ((i + 1) < orderByConditionFields.length) {
11276                                            if (orderByComparator.isAscending() ^ previous) {
11277                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11278                                            }
11279                                            else {
11280                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11281                                            }
11282                                    }
11283                                    else {
11284                                            if (orderByComparator.isAscending() ^ previous) {
11285                                                    query.append(WHERE_GREATER_THAN);
11286                                            }
11287                                            else {
11288                                                    query.append(WHERE_LESSER_THAN);
11289                                            }
11290                                    }
11291                            }
11292    
11293                            query.append(ORDER_BY_CLAUSE);
11294    
11295                            String[] orderByFields = orderByComparator.getOrderByFields();
11296    
11297                            for (int i = 0; i < orderByFields.length; i++) {
11298                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11299                                    query.append(orderByFields[i]);
11300    
11301                                    if ((i + 1) < orderByFields.length) {
11302                                            if (orderByComparator.isAscending() ^ previous) {
11303                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11304                                            }
11305                                            else {
11306                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11307                                            }
11308                                    }
11309                                    else {
11310                                            if (orderByComparator.isAscending() ^ previous) {
11311                                                    query.append(ORDER_BY_ASC);
11312                                            }
11313                                            else {
11314                                                    query.append(ORDER_BY_DESC);
11315                                            }
11316                                    }
11317                            }
11318                    }
11319    
11320                    else {
11321                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11322                    }
11323    
11324                    String sql = query.toString();
11325    
11326                    Query q = session.createQuery(sql);
11327    
11328                    q.setFirstResult(0);
11329                    q.setMaxResults(2);
11330    
11331                    QueryPos qPos = QueryPos.getInstance(q);
11332    
11333                    qPos.add(groupId);
11334    
11335                    qPos.add(categoryId);
11336    
11337                    qPos.add(threadId);
11338    
11339                    if (orderByComparator != null) {
11340                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11341    
11342                            for (Object value : values) {
11343                                    qPos.add(value);
11344                            }
11345                    }
11346    
11347                    List<MBMessage> list = q.list();
11348    
11349                    if (list.size() == 2) {
11350                            return list.get(1);
11351                    }
11352                    else {
11353                            return null;
11354                    }
11355            }
11356    
11357            /**
11358             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11359             *
11360             * @param groupId the group ID
11361             * @param categoryId the category ID
11362             * @param threadId the thread ID
11363             * @return the matching message-boards messages that the user has permission to view
11364             * @throws SystemException if a system exception occurred
11365             */
11366            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
11367                    long threadId) throws SystemException {
11368                    return filterFindByG_C_T(groupId, categoryId, threadId,
11369                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11370            }
11371    
11372            /**
11373             * 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;.
11374             *
11375             * <p>
11376             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11377             * </p>
11378             *
11379             * @param groupId the group ID
11380             * @param categoryId the category ID
11381             * @param threadId the thread ID
11382             * @param start the lower bound of the range of message-boards messages
11383             * @param end the upper bound of the range of message-boards messages (not inclusive)
11384             * @return the range of matching message-boards messages that the user has permission to view
11385             * @throws SystemException if a system exception occurred
11386             */
11387            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
11388                    long threadId, int start, int end) throws SystemException {
11389                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
11390            }
11391    
11392            /**
11393             * 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;.
11394             *
11395             * <p>
11396             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11397             * </p>
11398             *
11399             * @param groupId the group ID
11400             * @param categoryId the category ID
11401             * @param threadId the thread ID
11402             * @param start the lower bound of the range of message-boards messages
11403             * @param end the upper bound of the range of message-boards messages (not inclusive)
11404             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11405             * @return the ordered range of matching message-boards messages that the user has permission to view
11406             * @throws SystemException if a system exception occurred
11407             */
11408            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
11409                    long threadId, int start, int end, OrderByComparator orderByComparator)
11410                    throws SystemException {
11411                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11412                            return findByG_C_T(groupId, categoryId, threadId, start, end,
11413                                    orderByComparator);
11414                    }
11415    
11416                    StringBundler query = null;
11417    
11418                    if (orderByComparator != null) {
11419                            query = new StringBundler(5 +
11420                                            (orderByComparator.getOrderByFields().length * 3));
11421                    }
11422                    else {
11423                            query = new StringBundler(5);
11424                    }
11425    
11426                    if (getDB().isSupportsInlineDistinct()) {
11427                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11428                    }
11429                    else {
11430                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11431                    }
11432    
11433                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
11434    
11435                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
11436    
11437                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
11438    
11439                    if (!getDB().isSupportsInlineDistinct()) {
11440                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11441                    }
11442    
11443                    if (orderByComparator != null) {
11444                            if (getDB().isSupportsInlineDistinct()) {
11445                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11446                                            orderByComparator);
11447                            }
11448                            else {
11449                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11450                                            orderByComparator);
11451                            }
11452                    }
11453    
11454                    else {
11455                            if (getDB().isSupportsInlineDistinct()) {
11456                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11457                            }
11458                            else {
11459                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11460                            }
11461                    }
11462    
11463                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11464                                    MBMessage.class.getName(),
11465                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11466    
11467                    Session session = null;
11468    
11469                    try {
11470                            session = openSession();
11471    
11472                            SQLQuery q = session.createSQLQuery(sql);
11473    
11474                            if (getDB().isSupportsInlineDistinct()) {
11475                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11476                            }
11477                            else {
11478                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11479                            }
11480    
11481                            QueryPos qPos = QueryPos.getInstance(q);
11482    
11483                            qPos.add(groupId);
11484    
11485                            qPos.add(categoryId);
11486    
11487                            qPos.add(threadId);
11488    
11489                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11490                    }
11491                    catch (Exception e) {
11492                            throw processException(e);
11493                    }
11494                    finally {
11495                            closeSession(session);
11496                    }
11497            }
11498    
11499            /**
11500             * 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;.
11501             *
11502             * @param messageId the primary key of the current message-boards message
11503             * @param groupId the group ID
11504             * @param categoryId the category ID
11505             * @param threadId the thread ID
11506             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11507             * @return the previous, current, and next message-boards message
11508             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11509             * @throws SystemException if a system exception occurred
11510             */
11511            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
11512                    long groupId, long categoryId, long threadId,
11513                    OrderByComparator orderByComparator)
11514                    throws NoSuchMessageException, SystemException {
11515                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11516                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
11517                                    threadId, orderByComparator);
11518                    }
11519    
11520                    MBMessage mbMessage = findByPrimaryKey(messageId);
11521    
11522                    Session session = null;
11523    
11524                    try {
11525                            session = openSession();
11526    
11527                            MBMessage[] array = new MBMessageImpl[3];
11528    
11529                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
11530                                            groupId, categoryId, threadId, orderByComparator, true);
11531    
11532                            array[1] = mbMessage;
11533    
11534                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
11535                                            groupId, categoryId, threadId, orderByComparator, false);
11536    
11537                            return array;
11538                    }
11539                    catch (Exception e) {
11540                            throw processException(e);
11541                    }
11542                    finally {
11543                            closeSession(session);
11544                    }
11545            }
11546    
11547            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
11548                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
11549                    OrderByComparator orderByComparator, boolean previous) {
11550                    StringBundler query = null;
11551    
11552                    if (orderByComparator != null) {
11553                            query = new StringBundler(6 +
11554                                            (orderByComparator.getOrderByFields().length * 6));
11555                    }
11556                    else {
11557                            query = new StringBundler(3);
11558                    }
11559    
11560                    if (getDB().isSupportsInlineDistinct()) {
11561                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11562                    }
11563                    else {
11564                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11565                    }
11566    
11567                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
11568    
11569                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
11570    
11571                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
11572    
11573                    if (!getDB().isSupportsInlineDistinct()) {
11574                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11575                    }
11576    
11577                    if (orderByComparator != null) {
11578                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11579    
11580                            if (orderByConditionFields.length > 0) {
11581                                    query.append(WHERE_AND);
11582                            }
11583    
11584                            for (int i = 0; i < orderByConditionFields.length; i++) {
11585                                    if (getDB().isSupportsInlineDistinct()) {
11586                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11587                                    }
11588                                    else {
11589                                            query.append(_ORDER_BY_ENTITY_TABLE);
11590                                    }
11591    
11592                                    query.append(orderByConditionFields[i]);
11593    
11594                                    if ((i + 1) < orderByConditionFields.length) {
11595                                            if (orderByComparator.isAscending() ^ previous) {
11596                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11597                                            }
11598                                            else {
11599                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11600                                            }
11601                                    }
11602                                    else {
11603                                            if (orderByComparator.isAscending() ^ previous) {
11604                                                    query.append(WHERE_GREATER_THAN);
11605                                            }
11606                                            else {
11607                                                    query.append(WHERE_LESSER_THAN);
11608                                            }
11609                                    }
11610                            }
11611    
11612                            query.append(ORDER_BY_CLAUSE);
11613    
11614                            String[] orderByFields = orderByComparator.getOrderByFields();
11615    
11616                            for (int i = 0; i < orderByFields.length; i++) {
11617                                    if (getDB().isSupportsInlineDistinct()) {
11618                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11619                                    }
11620                                    else {
11621                                            query.append(_ORDER_BY_ENTITY_TABLE);
11622                                    }
11623    
11624                                    query.append(orderByFields[i]);
11625    
11626                                    if ((i + 1) < orderByFields.length) {
11627                                            if (orderByComparator.isAscending() ^ previous) {
11628                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11629                                            }
11630                                            else {
11631                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11632                                            }
11633                                    }
11634                                    else {
11635                                            if (orderByComparator.isAscending() ^ previous) {
11636                                                    query.append(ORDER_BY_ASC);
11637                                            }
11638                                            else {
11639                                                    query.append(ORDER_BY_DESC);
11640                                            }
11641                                    }
11642                            }
11643                    }
11644    
11645                    else {
11646                            if (getDB().isSupportsInlineDistinct()) {
11647                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11648                            }
11649                            else {
11650                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11651                            }
11652                    }
11653    
11654                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11655                                    MBMessage.class.getName(),
11656                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11657    
11658                    SQLQuery q = session.createSQLQuery(sql);
11659    
11660                    q.setFirstResult(0);
11661                    q.setMaxResults(2);
11662    
11663                    if (getDB().isSupportsInlineDistinct()) {
11664                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11665                    }
11666                    else {
11667                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11668                    }
11669    
11670                    QueryPos qPos = QueryPos.getInstance(q);
11671    
11672                    qPos.add(groupId);
11673    
11674                    qPos.add(categoryId);
11675    
11676                    qPos.add(threadId);
11677    
11678                    if (orderByComparator != null) {
11679                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11680    
11681                            for (Object value : values) {
11682                                    qPos.add(value);
11683                            }
11684                    }
11685    
11686                    List<MBMessage> list = q.list();
11687    
11688                    if (list.size() == 2) {
11689                            return list.get(1);
11690                    }
11691                    else {
11692                            return null;
11693                    }
11694            }
11695    
11696            /**
11697             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
11698             *
11699             * @param groupId the group ID
11700             * @param categoryId the category ID
11701             * @param status the status
11702             * @return the matching message-boards messages
11703             * @throws SystemException if a system exception occurred
11704             */
11705            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status)
11706                    throws SystemException {
11707                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
11708                            QueryUtil.ALL_POS, null);
11709            }
11710    
11711            /**
11712             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
11713             *
11714             * <p>
11715             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11716             * </p>
11717             *
11718             * @param groupId the group ID
11719             * @param categoryId the category ID
11720             * @param status the status
11721             * @param start the lower bound of the range of message-boards messages
11722             * @param end the upper bound of the range of message-boards messages (not inclusive)
11723             * @return the range of matching message-boards messages
11724             * @throws SystemException if a system exception occurred
11725             */
11726            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
11727                    int status, int start, int end) throws SystemException {
11728                    return findByG_C_S(groupId, categoryId, status, start, end, null);
11729            }
11730    
11731            /**
11732             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
11733             *
11734             * <p>
11735             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
11736             * </p>
11737             *
11738             * @param groupId the group ID
11739             * @param categoryId the category ID
11740             * @param status the status
11741             * @param start the lower bound of the range of message-boards messages
11742             * @param end the upper bound of the range of message-boards messages (not inclusive)
11743             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11744             * @return the ordered range of matching message-boards messages
11745             * @throws SystemException if a system exception occurred
11746             */
11747            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
11748                    int status, int start, int end, OrderByComparator orderByComparator)
11749                    throws SystemException {
11750                    FinderPath finderPath = null;
11751                    Object[] finderArgs = null;
11752    
11753                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11754                                    (orderByComparator == null)) {
11755                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
11756                            finderArgs = new Object[] { groupId, categoryId, status };
11757                    }
11758                    else {
11759                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
11760                            finderArgs = new Object[] {
11761                                            groupId, categoryId, status,
11762                                            
11763                                            start, end, orderByComparator
11764                                    };
11765                    }
11766    
11767                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
11768                                    finderArgs, this);
11769    
11770                    if ((list != null) && !list.isEmpty()) {
11771                            for (MBMessage mbMessage : list) {
11772                                    if ((groupId != mbMessage.getGroupId()) ||
11773                                                    (categoryId != mbMessage.getCategoryId()) ||
11774                                                    (status != mbMessage.getStatus())) {
11775                                            list = null;
11776    
11777                                            break;
11778                                    }
11779                            }
11780                    }
11781    
11782                    if (list == null) {
11783                            StringBundler query = null;
11784    
11785                            if (orderByComparator != null) {
11786                                    query = new StringBundler(5 +
11787                                                    (orderByComparator.getOrderByFields().length * 3));
11788                            }
11789                            else {
11790                                    query = new StringBundler(5);
11791                            }
11792    
11793                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11794    
11795                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
11796    
11797                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
11798    
11799                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
11800    
11801                            if (orderByComparator != null) {
11802                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11803                                            orderByComparator);
11804                            }
11805    
11806                            else {
11807                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11808                            }
11809    
11810                            String sql = query.toString();
11811    
11812                            Session session = null;
11813    
11814                            try {
11815                                    session = openSession();
11816    
11817                                    Query q = session.createQuery(sql);
11818    
11819                                    QueryPos qPos = QueryPos.getInstance(q);
11820    
11821                                    qPos.add(groupId);
11822    
11823                                    qPos.add(categoryId);
11824    
11825                                    qPos.add(status);
11826    
11827                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
11828                                                    end);
11829                            }
11830                            catch (Exception e) {
11831                                    throw processException(e);
11832                            }
11833                            finally {
11834                                    if (list == null) {
11835                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
11836                                    }
11837                                    else {
11838                                            cacheResult(list);
11839    
11840                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
11841                                    }
11842    
11843                                    closeSession(session);
11844                            }
11845                    }
11846    
11847                    return list;
11848            }
11849    
11850            /**
11851             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
11852             *
11853             * @param groupId the group ID
11854             * @param categoryId the category ID
11855             * @param status the status
11856             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11857             * @return the first matching message-boards message
11858             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11859             * @throws SystemException if a system exception occurred
11860             */
11861            public MBMessage findByG_C_S_First(long groupId, long categoryId,
11862                    int status, OrderByComparator orderByComparator)
11863                    throws NoSuchMessageException, SystemException {
11864                    MBMessage mbMessage = fetchByG_C_S_First(groupId, categoryId, status,
11865                                    orderByComparator);
11866    
11867                    if (mbMessage != null) {
11868                            return mbMessage;
11869                    }
11870    
11871                    StringBundler msg = new StringBundler(8);
11872    
11873                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11874    
11875                    msg.append("groupId=");
11876                    msg.append(groupId);
11877    
11878                    msg.append(", categoryId=");
11879                    msg.append(categoryId);
11880    
11881                    msg.append(", status=");
11882                    msg.append(status);
11883    
11884                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11885    
11886                    throw new NoSuchMessageException(msg.toString());
11887            }
11888    
11889            /**
11890             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
11891             *
11892             * @param groupId the group ID
11893             * @param categoryId the category ID
11894             * @param status the status
11895             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11896             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11897             * @throws SystemException if a system exception occurred
11898             */
11899            public MBMessage fetchByG_C_S_First(long groupId, long categoryId,
11900                    int status, OrderByComparator orderByComparator)
11901                    throws SystemException {
11902                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
11903                                    orderByComparator);
11904    
11905                    if (!list.isEmpty()) {
11906                            return list.get(0);
11907                    }
11908    
11909                    return null;
11910            }
11911    
11912            /**
11913             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
11914             *
11915             * @param groupId the group ID
11916             * @param categoryId the category ID
11917             * @param status the status
11918             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11919             * @return the last matching message-boards message
11920             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11921             * @throws SystemException if a system exception occurred
11922             */
11923            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
11924                    int status, OrderByComparator orderByComparator)
11925                    throws NoSuchMessageException, SystemException {
11926                    MBMessage mbMessage = fetchByG_C_S_Last(groupId, categoryId, status,
11927                                    orderByComparator);
11928    
11929                    if (mbMessage != null) {
11930                            return mbMessage;
11931                    }
11932    
11933                    StringBundler msg = new StringBundler(8);
11934    
11935                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11936    
11937                    msg.append("groupId=");
11938                    msg.append(groupId);
11939    
11940                    msg.append(", categoryId=");
11941                    msg.append(categoryId);
11942    
11943                    msg.append(", status=");
11944                    msg.append(status);
11945    
11946                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11947    
11948                    throw new NoSuchMessageException(msg.toString());
11949            }
11950    
11951            /**
11952             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
11953             *
11954             * @param groupId the group ID
11955             * @param categoryId the category ID
11956             * @param status the status
11957             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11958             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11959             * @throws SystemException if a system exception occurred
11960             */
11961            public MBMessage fetchByG_C_S_Last(long groupId, long categoryId,
11962                    int status, OrderByComparator orderByComparator)
11963                    throws SystemException {
11964                    int count = countByG_C_S(groupId, categoryId, status);
11965    
11966                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
11967                                    count - 1, count, orderByComparator);
11968    
11969                    if (!list.isEmpty()) {
11970                            return list.get(0);
11971                    }
11972    
11973                    return null;
11974            }
11975    
11976            /**
11977             * 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;.
11978             *
11979             * @param messageId the primary key of the current message-boards message
11980             * @param groupId the group ID
11981             * @param categoryId the category ID
11982             * @param status the status
11983             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11984             * @return the previous, current, and next message-boards message
11985             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11986             * @throws SystemException if a system exception occurred
11987             */
11988            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
11989                    long categoryId, int status, OrderByComparator orderByComparator)
11990                    throws NoSuchMessageException, SystemException {
11991                    MBMessage mbMessage = findByPrimaryKey(messageId);
11992    
11993                    Session session = null;
11994    
11995                    try {
11996                            session = openSession();
11997    
11998                            MBMessage[] array = new MBMessageImpl[3];
11999    
12000                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
12001                                            categoryId, status, orderByComparator, true);
12002    
12003                            array[1] = mbMessage;
12004    
12005                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
12006                                            categoryId, status, orderByComparator, false);
12007    
12008                            return array;
12009                    }
12010                    catch (Exception e) {
12011                            throw processException(e);
12012                    }
12013                    finally {
12014                            closeSession(session);
12015                    }
12016            }
12017    
12018            protected MBMessage getByG_C_S_PrevAndNext(Session session,
12019                    MBMessage mbMessage, long groupId, long categoryId, int status,
12020                    OrderByComparator orderByComparator, boolean previous) {
12021                    StringBundler query = null;
12022    
12023                    if (orderByComparator != null) {
12024                            query = new StringBundler(6 +
12025                                            (orderByComparator.getOrderByFields().length * 6));
12026                    }
12027                    else {
12028                            query = new StringBundler(3);
12029                    }
12030    
12031                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12032    
12033                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
12034    
12035                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
12036    
12037                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
12038    
12039                    if (orderByComparator != null) {
12040                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12041    
12042                            if (orderByConditionFields.length > 0) {
12043                                    query.append(WHERE_AND);
12044                            }
12045    
12046                            for (int i = 0; i < orderByConditionFields.length; i++) {
12047                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12048                                    query.append(orderByConditionFields[i]);
12049    
12050                                    if ((i + 1) < orderByConditionFields.length) {
12051                                            if (orderByComparator.isAscending() ^ previous) {
12052                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12053                                            }
12054                                            else {
12055                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12056                                            }
12057                                    }
12058                                    else {
12059                                            if (orderByComparator.isAscending() ^ previous) {
12060                                                    query.append(WHERE_GREATER_THAN);
12061                                            }
12062                                            else {
12063                                                    query.append(WHERE_LESSER_THAN);
12064                                            }
12065                                    }
12066                            }
12067    
12068                            query.append(ORDER_BY_CLAUSE);
12069    
12070                            String[] orderByFields = orderByComparator.getOrderByFields();
12071    
12072                            for (int i = 0; i < orderByFields.length; i++) {
12073                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12074                                    query.append(orderByFields[i]);
12075    
12076                                    if ((i + 1) < orderByFields.length) {
12077                                            if (orderByComparator.isAscending() ^ previous) {
12078                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12079                                            }
12080                                            else {
12081                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12082                                            }
12083                                    }
12084                                    else {
12085                                            if (orderByComparator.isAscending() ^ previous) {
12086                                                    query.append(ORDER_BY_ASC);
12087                                            }
12088                                            else {
12089                                                    query.append(ORDER_BY_DESC);
12090                                            }
12091                                    }
12092                            }
12093                    }
12094    
12095                    else {
12096                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12097                    }
12098    
12099                    String sql = query.toString();
12100    
12101                    Query q = session.createQuery(sql);
12102    
12103                    q.setFirstResult(0);
12104                    q.setMaxResults(2);
12105    
12106                    QueryPos qPos = QueryPos.getInstance(q);
12107    
12108                    qPos.add(groupId);
12109    
12110                    qPos.add(categoryId);
12111    
12112                    qPos.add(status);
12113    
12114                    if (orderByComparator != null) {
12115                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12116    
12117                            for (Object value : values) {
12118                                    qPos.add(value);
12119                            }
12120                    }
12121    
12122                    List<MBMessage> list = q.list();
12123    
12124                    if (list.size() == 2) {
12125                            return list.get(1);
12126                    }
12127                    else {
12128                            return null;
12129                    }
12130            }
12131    
12132            /**
12133             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
12134             *
12135             * @param groupId the group ID
12136             * @param categoryId the category ID
12137             * @param status the status
12138             * @return the matching message-boards messages that the user has permission to view
12139             * @throws SystemException if a system exception occurred
12140             */
12141            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
12142                    int status) throws SystemException {
12143                    return filterFindByG_C_S(groupId, categoryId, status,
12144                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12145            }
12146    
12147            /**
12148             * 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;.
12149             *
12150             * <p>
12151             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12152             * </p>
12153             *
12154             * @param groupId the group ID
12155             * @param categoryId the category ID
12156             * @param status the status
12157             * @param start the lower bound of the range of message-boards messages
12158             * @param end the upper bound of the range of message-boards messages (not inclusive)
12159             * @return the range of matching message-boards messages that the user has permission to view
12160             * @throws SystemException if a system exception occurred
12161             */
12162            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
12163                    int status, int start, int end) throws SystemException {
12164                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
12165            }
12166    
12167            /**
12168             * 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;.
12169             *
12170             * <p>
12171             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12172             * </p>
12173             *
12174             * @param groupId the group ID
12175             * @param categoryId the category ID
12176             * @param status the status
12177             * @param start the lower bound of the range of message-boards messages
12178             * @param end the upper bound of the range of message-boards messages (not inclusive)
12179             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12180             * @return the ordered range of matching message-boards messages that the user has permission to view
12181             * @throws SystemException if a system exception occurred
12182             */
12183            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
12184                    int status, int start, int end, OrderByComparator orderByComparator)
12185                    throws SystemException {
12186                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12187                            return findByG_C_S(groupId, categoryId, status, start, end,
12188                                    orderByComparator);
12189                    }
12190    
12191                    StringBundler query = null;
12192    
12193                    if (orderByComparator != null) {
12194                            query = new StringBundler(5 +
12195                                            (orderByComparator.getOrderByFields().length * 3));
12196                    }
12197                    else {
12198                            query = new StringBundler(5);
12199                    }
12200    
12201                    if (getDB().isSupportsInlineDistinct()) {
12202                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12203                    }
12204                    else {
12205                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12206                    }
12207    
12208                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
12209    
12210                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
12211    
12212                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
12213    
12214                    if (!getDB().isSupportsInlineDistinct()) {
12215                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12216                    }
12217    
12218                    if (orderByComparator != null) {
12219                            if (getDB().isSupportsInlineDistinct()) {
12220                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12221                                            orderByComparator);
12222                            }
12223                            else {
12224                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12225                                            orderByComparator);
12226                            }
12227                    }
12228    
12229                    else {
12230                            if (getDB().isSupportsInlineDistinct()) {
12231                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12232                            }
12233                            else {
12234                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12235                            }
12236                    }
12237    
12238                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12239                                    MBMessage.class.getName(),
12240                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12241    
12242                    Session session = null;
12243    
12244                    try {
12245                            session = openSession();
12246    
12247                            SQLQuery q = session.createSQLQuery(sql);
12248    
12249                            if (getDB().isSupportsInlineDistinct()) {
12250                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12251                            }
12252                            else {
12253                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12254                            }
12255    
12256                            QueryPos qPos = QueryPos.getInstance(q);
12257    
12258                            qPos.add(groupId);
12259    
12260                            qPos.add(categoryId);
12261    
12262                            qPos.add(status);
12263    
12264                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
12265                    }
12266                    catch (Exception e) {
12267                            throw processException(e);
12268                    }
12269                    finally {
12270                            closeSession(session);
12271                    }
12272            }
12273    
12274            /**
12275             * 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;.
12276             *
12277             * @param messageId the primary key of the current message-boards message
12278             * @param groupId the group ID
12279             * @param categoryId the category ID
12280             * @param status the status
12281             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12282             * @return the previous, current, and next message-boards message
12283             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12284             * @throws SystemException if a system exception occurred
12285             */
12286            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
12287                    long groupId, long categoryId, int status,
12288                    OrderByComparator orderByComparator)
12289                    throws NoSuchMessageException, SystemException {
12290                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12291                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
12292                                    status, orderByComparator);
12293                    }
12294    
12295                    MBMessage mbMessage = findByPrimaryKey(messageId);
12296    
12297                    Session session = null;
12298    
12299                    try {
12300                            session = openSession();
12301    
12302                            MBMessage[] array = new MBMessageImpl[3];
12303    
12304                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
12305                                            groupId, categoryId, status, orderByComparator, true);
12306    
12307                            array[1] = mbMessage;
12308    
12309                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
12310                                            groupId, categoryId, status, orderByComparator, false);
12311    
12312                            return array;
12313                    }
12314                    catch (Exception e) {
12315                            throw processException(e);
12316                    }
12317                    finally {
12318                            closeSession(session);
12319                    }
12320            }
12321    
12322            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
12323                    MBMessage mbMessage, long groupId, long categoryId, int status,
12324                    OrderByComparator orderByComparator, boolean previous) {
12325                    StringBundler query = null;
12326    
12327                    if (orderByComparator != null) {
12328                            query = new StringBundler(6 +
12329                                            (orderByComparator.getOrderByFields().length * 6));
12330                    }
12331                    else {
12332                            query = new StringBundler(3);
12333                    }
12334    
12335                    if (getDB().isSupportsInlineDistinct()) {
12336                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12337                    }
12338                    else {
12339                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12340                    }
12341    
12342                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
12343    
12344                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
12345    
12346                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
12347    
12348                    if (!getDB().isSupportsInlineDistinct()) {
12349                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12350                    }
12351    
12352                    if (orderByComparator != null) {
12353                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12354    
12355                            if (orderByConditionFields.length > 0) {
12356                                    query.append(WHERE_AND);
12357                            }
12358    
12359                            for (int i = 0; i < orderByConditionFields.length; i++) {
12360                                    if (getDB().isSupportsInlineDistinct()) {
12361                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12362                                    }
12363                                    else {
12364                                            query.append(_ORDER_BY_ENTITY_TABLE);
12365                                    }
12366    
12367                                    query.append(orderByConditionFields[i]);
12368    
12369                                    if ((i + 1) < orderByConditionFields.length) {
12370                                            if (orderByComparator.isAscending() ^ previous) {
12371                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12372                                            }
12373                                            else {
12374                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12375                                            }
12376                                    }
12377                                    else {
12378                                            if (orderByComparator.isAscending() ^ previous) {
12379                                                    query.append(WHERE_GREATER_THAN);
12380                                            }
12381                                            else {
12382                                                    query.append(WHERE_LESSER_THAN);
12383                                            }
12384                                    }
12385                            }
12386    
12387                            query.append(ORDER_BY_CLAUSE);
12388    
12389                            String[] orderByFields = orderByComparator.getOrderByFields();
12390    
12391                            for (int i = 0; i < orderByFields.length; i++) {
12392                                    if (getDB().isSupportsInlineDistinct()) {
12393                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12394                                    }
12395                                    else {
12396                                            query.append(_ORDER_BY_ENTITY_TABLE);
12397                                    }
12398    
12399                                    query.append(orderByFields[i]);
12400    
12401                                    if ((i + 1) < orderByFields.length) {
12402                                            if (orderByComparator.isAscending() ^ previous) {
12403                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12404                                            }
12405                                            else {
12406                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12407                                            }
12408                                    }
12409                                    else {
12410                                            if (orderByComparator.isAscending() ^ previous) {
12411                                                    query.append(ORDER_BY_ASC);
12412                                            }
12413                                            else {
12414                                                    query.append(ORDER_BY_DESC);
12415                                            }
12416                                    }
12417                            }
12418                    }
12419    
12420                    else {
12421                            if (getDB().isSupportsInlineDistinct()) {
12422                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12423                            }
12424                            else {
12425                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12426                            }
12427                    }
12428    
12429                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12430                                    MBMessage.class.getName(),
12431                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12432    
12433                    SQLQuery q = session.createSQLQuery(sql);
12434    
12435                    q.setFirstResult(0);
12436                    q.setMaxResults(2);
12437    
12438                    if (getDB().isSupportsInlineDistinct()) {
12439                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12440                    }
12441                    else {
12442                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12443                    }
12444    
12445                    QueryPos qPos = QueryPos.getInstance(q);
12446    
12447                    qPos.add(groupId);
12448    
12449                    qPos.add(categoryId);
12450    
12451                    qPos.add(status);
12452    
12453                    if (orderByComparator != null) {
12454                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12455    
12456                            for (Object value : values) {
12457                                    qPos.add(value);
12458                            }
12459                    }
12460    
12461                    List<MBMessage> list = q.list();
12462    
12463                    if (list.size() == 2) {
12464                            return list.get(1);
12465                    }
12466                    else {
12467                            return null;
12468                    }
12469            }
12470    
12471            /**
12472             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12473             *
12474             * @param userId the user ID
12475             * @param classNameId the class name ID
12476             * @param classPK the class p k
12477             * @return the matching message-boards messages
12478             * @throws SystemException if a system exception occurred
12479             */
12480            public List<MBMessage> findByU_C_C(long userId, long classNameId,
12481                    long classPK) throws SystemException {
12482                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
12483                            QueryUtil.ALL_POS, null);
12484            }
12485    
12486            /**
12487             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12488             *
12489             * <p>
12490             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12491             * </p>
12492             *
12493             * @param userId the user ID
12494             * @param classNameId the class name ID
12495             * @param classPK the class p k
12496             * @param start the lower bound of the range of message-boards messages
12497             * @param end the upper bound of the range of message-boards messages (not inclusive)
12498             * @return the range of matching message-boards messages
12499             * @throws SystemException if a system exception occurred
12500             */
12501            public List<MBMessage> findByU_C_C(long userId, long classNameId,
12502                    long classPK, int start, int end) throws SystemException {
12503                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
12504            }
12505    
12506            /**
12507             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12508             *
12509             * <p>
12510             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12511             * </p>
12512             *
12513             * @param userId the user ID
12514             * @param classNameId the class name ID
12515             * @param classPK the class p k
12516             * @param start the lower bound of the range of message-boards messages
12517             * @param end the upper bound of the range of message-boards messages (not inclusive)
12518             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12519             * @return the ordered range of matching message-boards messages
12520             * @throws SystemException if a system exception occurred
12521             */
12522            public List<MBMessage> findByU_C_C(long userId, long classNameId,
12523                    long classPK, int start, int end, OrderByComparator orderByComparator)
12524                    throws SystemException {
12525                    FinderPath finderPath = null;
12526                    Object[] finderArgs = null;
12527    
12528                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12529                                    (orderByComparator == null)) {
12530                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
12531                            finderArgs = new Object[] { userId, classNameId, classPK };
12532                    }
12533                    else {
12534                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
12535                            finderArgs = new Object[] {
12536                                            userId, classNameId, classPK,
12537                                            
12538                                            start, end, orderByComparator
12539                                    };
12540                    }
12541    
12542                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12543                                    finderArgs, this);
12544    
12545                    if ((list != null) && !list.isEmpty()) {
12546                            for (MBMessage mbMessage : list) {
12547                                    if ((userId != mbMessage.getUserId()) ||
12548                                                    (classNameId != mbMessage.getClassNameId()) ||
12549                                                    (classPK != mbMessage.getClassPK())) {
12550                                            list = null;
12551    
12552                                            break;
12553                                    }
12554                            }
12555                    }
12556    
12557                    if (list == null) {
12558                            StringBundler query = null;
12559    
12560                            if (orderByComparator != null) {
12561                                    query = new StringBundler(5 +
12562                                                    (orderByComparator.getOrderByFields().length * 3));
12563                            }
12564                            else {
12565                                    query = new StringBundler(5);
12566                            }
12567    
12568                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12569    
12570                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
12571    
12572                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
12573    
12574                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
12575    
12576                            if (orderByComparator != null) {
12577                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12578                                            orderByComparator);
12579                            }
12580    
12581                            else {
12582                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12583                            }
12584    
12585                            String sql = query.toString();
12586    
12587                            Session session = null;
12588    
12589                            try {
12590                                    session = openSession();
12591    
12592                                    Query q = session.createQuery(sql);
12593    
12594                                    QueryPos qPos = QueryPos.getInstance(q);
12595    
12596                                    qPos.add(userId);
12597    
12598                                    qPos.add(classNameId);
12599    
12600                                    qPos.add(classPK);
12601    
12602                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
12603                                                    end);
12604                            }
12605                            catch (Exception e) {
12606                                    throw processException(e);
12607                            }
12608                            finally {
12609                                    if (list == null) {
12610                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
12611                                    }
12612                                    else {
12613                                            cacheResult(list);
12614    
12615                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
12616                                    }
12617    
12618                                    closeSession(session);
12619                            }
12620                    }
12621    
12622                    return list;
12623            }
12624    
12625            /**
12626             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12627             *
12628             * @param userId the user ID
12629             * @param classNameId the class name ID
12630             * @param classPK the class p k
12631             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12632             * @return the first matching message-boards message
12633             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12634             * @throws SystemException if a system exception occurred
12635             */
12636            public MBMessage findByU_C_C_First(long userId, long classNameId,
12637                    long classPK, OrderByComparator orderByComparator)
12638                    throws NoSuchMessageException, SystemException {
12639                    MBMessage mbMessage = fetchByU_C_C_First(userId, classNameId, classPK,
12640                                    orderByComparator);
12641    
12642                    if (mbMessage != null) {
12643                            return mbMessage;
12644                    }
12645    
12646                    StringBundler msg = new StringBundler(8);
12647    
12648                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12649    
12650                    msg.append("userId=");
12651                    msg.append(userId);
12652    
12653                    msg.append(", classNameId=");
12654                    msg.append(classNameId);
12655    
12656                    msg.append(", classPK=");
12657                    msg.append(classPK);
12658    
12659                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12660    
12661                    throw new NoSuchMessageException(msg.toString());
12662            }
12663    
12664            /**
12665             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12666             *
12667             * @param userId the user ID
12668             * @param classNameId the class name ID
12669             * @param classPK the class p k
12670             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12671             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12672             * @throws SystemException if a system exception occurred
12673             */
12674            public MBMessage fetchByU_C_C_First(long userId, long classNameId,
12675                    long classPK, OrderByComparator orderByComparator)
12676                    throws SystemException {
12677                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
12678                                    orderByComparator);
12679    
12680                    if (!list.isEmpty()) {
12681                            return list.get(0);
12682                    }
12683    
12684                    return null;
12685            }
12686    
12687            /**
12688             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12689             *
12690             * @param userId the user ID
12691             * @param classNameId the class name ID
12692             * @param classPK the class p k
12693             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12694             * @return the last matching message-boards message
12695             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12696             * @throws SystemException if a system exception occurred
12697             */
12698            public MBMessage findByU_C_C_Last(long userId, long classNameId,
12699                    long classPK, OrderByComparator orderByComparator)
12700                    throws NoSuchMessageException, SystemException {
12701                    MBMessage mbMessage = fetchByU_C_C_Last(userId, classNameId, classPK,
12702                                    orderByComparator);
12703    
12704                    if (mbMessage != null) {
12705                            return mbMessage;
12706                    }
12707    
12708                    StringBundler msg = new StringBundler(8);
12709    
12710                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12711    
12712                    msg.append("userId=");
12713                    msg.append(userId);
12714    
12715                    msg.append(", classNameId=");
12716                    msg.append(classNameId);
12717    
12718                    msg.append(", classPK=");
12719                    msg.append(classPK);
12720    
12721                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12722    
12723                    throw new NoSuchMessageException(msg.toString());
12724            }
12725    
12726            /**
12727             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
12728             *
12729             * @param userId the user ID
12730             * @param classNameId the class name ID
12731             * @param classPK the class p k
12732             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12733             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12734             * @throws SystemException if a system exception occurred
12735             */
12736            public MBMessage fetchByU_C_C_Last(long userId, long classNameId,
12737                    long classPK, OrderByComparator orderByComparator)
12738                    throws SystemException {
12739                    int count = countByU_C_C(userId, classNameId, classPK);
12740    
12741                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
12742                                    count - 1, count, orderByComparator);
12743    
12744                    if (!list.isEmpty()) {
12745                            return list.get(0);
12746                    }
12747    
12748                    return null;
12749            }
12750    
12751            /**
12752             * 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;.
12753             *
12754             * @param messageId the primary key of the current message-boards message
12755             * @param userId the user ID
12756             * @param classNameId the class name ID
12757             * @param classPK the class p k
12758             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12759             * @return the previous, current, and next message-boards message
12760             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12761             * @throws SystemException if a system exception occurred
12762             */
12763            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
12764                    long classNameId, long classPK, OrderByComparator orderByComparator)
12765                    throws NoSuchMessageException, SystemException {
12766                    MBMessage mbMessage = findByPrimaryKey(messageId);
12767    
12768                    Session session = null;
12769    
12770                    try {
12771                            session = openSession();
12772    
12773                            MBMessage[] array = new MBMessageImpl[3];
12774    
12775                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
12776                                            classNameId, classPK, orderByComparator, true);
12777    
12778                            array[1] = mbMessage;
12779    
12780                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
12781                                            classNameId, classPK, orderByComparator, false);
12782    
12783                            return array;
12784                    }
12785                    catch (Exception e) {
12786                            throw processException(e);
12787                    }
12788                    finally {
12789                            closeSession(session);
12790                    }
12791            }
12792    
12793            protected MBMessage getByU_C_C_PrevAndNext(Session session,
12794                    MBMessage mbMessage, long userId, long classNameId, long classPK,
12795                    OrderByComparator orderByComparator, boolean previous) {
12796                    StringBundler query = null;
12797    
12798                    if (orderByComparator != null) {
12799                            query = new StringBundler(6 +
12800                                            (orderByComparator.getOrderByFields().length * 6));
12801                    }
12802                    else {
12803                            query = new StringBundler(3);
12804                    }
12805    
12806                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12807    
12808                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
12809    
12810                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
12811    
12812                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
12813    
12814                    if (orderByComparator != null) {
12815                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12816    
12817                            if (orderByConditionFields.length > 0) {
12818                                    query.append(WHERE_AND);
12819                            }
12820    
12821                            for (int i = 0; i < orderByConditionFields.length; i++) {
12822                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12823                                    query.append(orderByConditionFields[i]);
12824    
12825                                    if ((i + 1) < orderByConditionFields.length) {
12826                                            if (orderByComparator.isAscending() ^ previous) {
12827                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12828                                            }
12829                                            else {
12830                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12831                                            }
12832                                    }
12833                                    else {
12834                                            if (orderByComparator.isAscending() ^ previous) {
12835                                                    query.append(WHERE_GREATER_THAN);
12836                                            }
12837                                            else {
12838                                                    query.append(WHERE_LESSER_THAN);
12839                                            }
12840                                    }
12841                            }
12842    
12843                            query.append(ORDER_BY_CLAUSE);
12844    
12845                            String[] orderByFields = orderByComparator.getOrderByFields();
12846    
12847                            for (int i = 0; i < orderByFields.length; i++) {
12848                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12849                                    query.append(orderByFields[i]);
12850    
12851                                    if ((i + 1) < orderByFields.length) {
12852                                            if (orderByComparator.isAscending() ^ previous) {
12853                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12854                                            }
12855                                            else {
12856                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12857                                            }
12858                                    }
12859                                    else {
12860                                            if (orderByComparator.isAscending() ^ previous) {
12861                                                    query.append(ORDER_BY_ASC);
12862                                            }
12863                                            else {
12864                                                    query.append(ORDER_BY_DESC);
12865                                            }
12866                                    }
12867                            }
12868                    }
12869    
12870                    else {
12871                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12872                    }
12873    
12874                    String sql = query.toString();
12875    
12876                    Query q = session.createQuery(sql);
12877    
12878                    q.setFirstResult(0);
12879                    q.setMaxResults(2);
12880    
12881                    QueryPos qPos = QueryPos.getInstance(q);
12882    
12883                    qPos.add(userId);
12884    
12885                    qPos.add(classNameId);
12886    
12887                    qPos.add(classPK);
12888    
12889                    if (orderByComparator != null) {
12890                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12891    
12892                            for (Object value : values) {
12893                                    qPos.add(value);
12894                            }
12895                    }
12896    
12897                    List<MBMessage> list = q.list();
12898    
12899                    if (list.size() == 2) {
12900                            return list.get(1);
12901                    }
12902                    else {
12903                            return null;
12904                    }
12905            }
12906    
12907            /**
12908             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
12909             *
12910             * @param userId the user ID
12911             * @param classNameId the class name ID
12912             * @param status the status
12913             * @return the matching message-boards messages
12914             * @throws SystemException if a system exception occurred
12915             */
12916            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status)
12917                    throws SystemException {
12918                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
12919                            QueryUtil.ALL_POS, null);
12920            }
12921    
12922            /**
12923             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
12924             *
12925             * <p>
12926             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12927             * </p>
12928             *
12929             * @param userId the user ID
12930             * @param classNameId the class name ID
12931             * @param status the status
12932             * @param start the lower bound of the range of message-boards messages
12933             * @param end the upper bound of the range of message-boards messages (not inclusive)
12934             * @return the range of matching message-boards messages
12935             * @throws SystemException if a system exception occurred
12936             */
12937            public List<MBMessage> findByU_C_S(long userId, long classNameId,
12938                    int status, int start, int end) throws SystemException {
12939                    return findByU_C_S(userId, classNameId, status, start, end, null);
12940            }
12941    
12942            /**
12943             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
12944             *
12945             * <p>
12946             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
12947             * </p>
12948             *
12949             * @param userId the user ID
12950             * @param classNameId the class name ID
12951             * @param status the status
12952             * @param start the lower bound of the range of message-boards messages
12953             * @param end the upper bound of the range of message-boards messages (not inclusive)
12954             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12955             * @return the ordered range of matching message-boards messages
12956             * @throws SystemException if a system exception occurred
12957             */
12958            public List<MBMessage> findByU_C_S(long userId, long classNameId,
12959                    int status, int start, int end, OrderByComparator orderByComparator)
12960                    throws SystemException {
12961                    FinderPath finderPath = null;
12962                    Object[] finderArgs = null;
12963    
12964                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12965                                    (orderByComparator == null)) {
12966                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
12967                            finderArgs = new Object[] { userId, classNameId, status };
12968                    }
12969                    else {
12970                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
12971                            finderArgs = new Object[] {
12972                                            userId, classNameId, status,
12973                                            
12974                                            start, end, orderByComparator
12975                                    };
12976                    }
12977    
12978                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12979                                    finderArgs, this);
12980    
12981                    if ((list != null) && !list.isEmpty()) {
12982                            for (MBMessage mbMessage : list) {
12983                                    if ((userId != mbMessage.getUserId()) ||
12984                                                    (classNameId != mbMessage.getClassNameId()) ||
12985                                                    (status != mbMessage.getStatus())) {
12986                                            list = null;
12987    
12988                                            break;
12989                                    }
12990                            }
12991                    }
12992    
12993                    if (list == null) {
12994                            StringBundler query = null;
12995    
12996                            if (orderByComparator != null) {
12997                                    query = new StringBundler(5 +
12998                                                    (orderByComparator.getOrderByFields().length * 3));
12999                            }
13000                            else {
13001                                    query = new StringBundler(5);
13002                            }
13003    
13004                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13005    
13006                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
13007    
13008                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
13009    
13010                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
13011    
13012                            if (orderByComparator != null) {
13013                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13014                                            orderByComparator);
13015                            }
13016    
13017                            else {
13018                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13019                            }
13020    
13021                            String sql = query.toString();
13022    
13023                            Session session = null;
13024    
13025                            try {
13026                                    session = openSession();
13027    
13028                                    Query q = session.createQuery(sql);
13029    
13030                                    QueryPos qPos = QueryPos.getInstance(q);
13031    
13032                                    qPos.add(userId);
13033    
13034                                    qPos.add(classNameId);
13035    
13036                                    qPos.add(status);
13037    
13038                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
13039                                                    end);
13040                            }
13041                            catch (Exception e) {
13042                                    throw processException(e);
13043                            }
13044                            finally {
13045                                    if (list == null) {
13046                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
13047                                    }
13048                                    else {
13049                                            cacheResult(list);
13050    
13051                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
13052                                    }
13053    
13054                                    closeSession(session);
13055                            }
13056                    }
13057    
13058                    return list;
13059            }
13060    
13061            /**
13062             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
13063             *
13064             * @param userId the user ID
13065             * @param classNameId the class name ID
13066             * @param status the status
13067             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13068             * @return the first matching message-boards message
13069             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13070             * @throws SystemException if a system exception occurred
13071             */
13072            public MBMessage findByU_C_S_First(long userId, long classNameId,
13073                    int status, OrderByComparator orderByComparator)
13074                    throws NoSuchMessageException, SystemException {
13075                    MBMessage mbMessage = fetchByU_C_S_First(userId, classNameId, status,
13076                                    orderByComparator);
13077    
13078                    if (mbMessage != null) {
13079                            return mbMessage;
13080                    }
13081    
13082                    StringBundler msg = new StringBundler(8);
13083    
13084                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13085    
13086                    msg.append("userId=");
13087                    msg.append(userId);
13088    
13089                    msg.append(", classNameId=");
13090                    msg.append(classNameId);
13091    
13092                    msg.append(", status=");
13093                    msg.append(status);
13094    
13095                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13096    
13097                    throw new NoSuchMessageException(msg.toString());
13098            }
13099    
13100            /**
13101             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
13102             *
13103             * @param userId the user ID
13104             * @param classNameId the class name ID
13105             * @param status the status
13106             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13107             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13108             * @throws SystemException if a system exception occurred
13109             */
13110            public MBMessage fetchByU_C_S_First(long userId, long classNameId,
13111                    int status, OrderByComparator orderByComparator)
13112                    throws SystemException {
13113                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
13114                                    orderByComparator);
13115    
13116                    if (!list.isEmpty()) {
13117                            return list.get(0);
13118                    }
13119    
13120                    return null;
13121            }
13122    
13123            /**
13124             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
13125             *
13126             * @param userId the user ID
13127             * @param classNameId the class name ID
13128             * @param status the status
13129             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13130             * @return the last matching message-boards message
13131             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13132             * @throws SystemException if a system exception occurred
13133             */
13134            public MBMessage findByU_C_S_Last(long userId, long classNameId,
13135                    int status, OrderByComparator orderByComparator)
13136                    throws NoSuchMessageException, SystemException {
13137                    MBMessage mbMessage = fetchByU_C_S_Last(userId, classNameId, status,
13138                                    orderByComparator);
13139    
13140                    if (mbMessage != null) {
13141                            return mbMessage;
13142                    }
13143    
13144                    StringBundler msg = new StringBundler(8);
13145    
13146                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13147    
13148                    msg.append("userId=");
13149                    msg.append(userId);
13150    
13151                    msg.append(", classNameId=");
13152                    msg.append(classNameId);
13153    
13154                    msg.append(", status=");
13155                    msg.append(status);
13156    
13157                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13158    
13159                    throw new NoSuchMessageException(msg.toString());
13160            }
13161    
13162            /**
13163             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
13164             *
13165             * @param userId the user ID
13166             * @param classNameId the class name ID
13167             * @param status the status
13168             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13169             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13170             * @throws SystemException if a system exception occurred
13171             */
13172            public MBMessage fetchByU_C_S_Last(long userId, long classNameId,
13173                    int status, OrderByComparator orderByComparator)
13174                    throws SystemException {
13175                    int count = countByU_C_S(userId, classNameId, status);
13176    
13177                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
13178                                    count - 1, count, orderByComparator);
13179    
13180                    if (!list.isEmpty()) {
13181                            return list.get(0);
13182                    }
13183    
13184                    return null;
13185            }
13186    
13187            /**
13188             * 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;.
13189             *
13190             * @param messageId the primary key of the current message-boards message
13191             * @param userId the user ID
13192             * @param classNameId the class name ID
13193             * @param status the status
13194             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13195             * @return the previous, current, and next message-boards message
13196             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13197             * @throws SystemException if a system exception occurred
13198             */
13199            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
13200                    long classNameId, int status, OrderByComparator orderByComparator)
13201                    throws NoSuchMessageException, SystemException {
13202                    MBMessage mbMessage = findByPrimaryKey(messageId);
13203    
13204                    Session session = null;
13205    
13206                    try {
13207                            session = openSession();
13208    
13209                            MBMessage[] array = new MBMessageImpl[3];
13210    
13211                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
13212                                            classNameId, status, orderByComparator, true);
13213    
13214                            array[1] = mbMessage;
13215    
13216                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
13217                                            classNameId, status, orderByComparator, false);
13218    
13219                            return array;
13220                    }
13221                    catch (Exception e) {
13222                            throw processException(e);
13223                    }
13224                    finally {
13225                            closeSession(session);
13226                    }
13227            }
13228    
13229            protected MBMessage getByU_C_S_PrevAndNext(Session session,
13230                    MBMessage mbMessage, long userId, long classNameId, int status,
13231                    OrderByComparator orderByComparator, boolean previous) {
13232                    StringBundler query = null;
13233    
13234                    if (orderByComparator != null) {
13235                            query = new StringBundler(6 +
13236                                            (orderByComparator.getOrderByFields().length * 6));
13237                    }
13238                    else {
13239                            query = new StringBundler(3);
13240                    }
13241    
13242                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13243    
13244                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
13245    
13246                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
13247    
13248                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
13249    
13250                    if (orderByComparator != null) {
13251                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13252    
13253                            if (orderByConditionFields.length > 0) {
13254                                    query.append(WHERE_AND);
13255                            }
13256    
13257                            for (int i = 0; i < orderByConditionFields.length; i++) {
13258                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13259                                    query.append(orderByConditionFields[i]);
13260    
13261                                    if ((i + 1) < orderByConditionFields.length) {
13262                                            if (orderByComparator.isAscending() ^ previous) {
13263                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13264                                            }
13265                                            else {
13266                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13267                                            }
13268                                    }
13269                                    else {
13270                                            if (orderByComparator.isAscending() ^ previous) {
13271                                                    query.append(WHERE_GREATER_THAN);
13272                                            }
13273                                            else {
13274                                                    query.append(WHERE_LESSER_THAN);
13275                                            }
13276                                    }
13277                            }
13278    
13279                            query.append(ORDER_BY_CLAUSE);
13280    
13281                            String[] orderByFields = orderByComparator.getOrderByFields();
13282    
13283                            for (int i = 0; i < orderByFields.length; i++) {
13284                                    query.append(_ORDER_BY_ENTITY_ALIAS);
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                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13308                    }
13309    
13310                    String sql = query.toString();
13311    
13312                    Query q = session.createQuery(sql);
13313    
13314                    q.setFirstResult(0);
13315                    q.setMaxResults(2);
13316    
13317                    QueryPos qPos = QueryPos.getInstance(q);
13318    
13319                    qPos.add(userId);
13320    
13321                    qPos.add(classNameId);
13322    
13323                    qPos.add(status);
13324    
13325                    if (orderByComparator != null) {
13326                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13327    
13328                            for (Object value : values) {
13329                                    qPos.add(value);
13330                            }
13331                    }
13332    
13333                    List<MBMessage> list = q.list();
13334    
13335                    if (list.size() == 2) {
13336                            return list.get(1);
13337                    }
13338                    else {
13339                            return null;
13340                    }
13341            }
13342    
13343            /**
13344             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
13345             *
13346             * <p>
13347             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13348             * </p>
13349             *
13350             * @param userId the user ID
13351             * @param classNameIds the class name IDs
13352             * @param status the status
13353             * @return the matching message-boards messages
13354             * @throws SystemException if a system exception occurred
13355             */
13356            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
13357                    int status) throws SystemException {
13358                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
13359                            QueryUtil.ALL_POS, null);
13360            }
13361    
13362            /**
13363             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
13364             *
13365             * <p>
13366             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13367             * </p>
13368             *
13369             * @param userId the user ID
13370             * @param classNameIds the class name IDs
13371             * @param status the status
13372             * @param start the lower bound of the range of message-boards messages
13373             * @param end the upper bound of the range of message-boards messages (not inclusive)
13374             * @return the range of matching message-boards messages
13375             * @throws SystemException if a system exception occurred
13376             */
13377            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
13378                    int status, int start, int end) throws SystemException {
13379                    return findByU_C_S(userId, classNameIds, status, start, end, null);
13380            }
13381    
13382            /**
13383             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
13384             *
13385             * <p>
13386             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13387             * </p>
13388             *
13389             * @param userId the user ID
13390             * @param classNameIds the class name IDs
13391             * @param status the status
13392             * @param start the lower bound of the range of message-boards messages
13393             * @param end the upper bound of the range of message-boards messages (not inclusive)
13394             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13395             * @return the ordered range of matching message-boards messages
13396             * @throws SystemException if a system exception occurred
13397             */
13398            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
13399                    int status, int start, int end, OrderByComparator orderByComparator)
13400                    throws SystemException {
13401                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
13402                    Object[] finderArgs = null;
13403    
13404                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13405                                    (orderByComparator == null)) {
13406                            finderArgs = new Object[] {
13407                                            userId, StringUtil.merge(classNameIds), status
13408                                    };
13409                    }
13410                    else {
13411                            finderArgs = new Object[] {
13412                                            userId, StringUtil.merge(classNameIds), status,
13413                                            
13414                                            start, end, orderByComparator
13415                                    };
13416                    }
13417    
13418                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
13419                                    finderArgs, this);
13420    
13421                    if ((list != null) && !list.isEmpty()) {
13422                            for (MBMessage mbMessage : list) {
13423                                    if ((userId != mbMessage.getUserId()) ||
13424                                                    !ArrayUtil.contains(classNameIds,
13425                                                            mbMessage.getClassNameId()) ||
13426                                                    (status != mbMessage.getStatus())) {
13427                                            list = null;
13428    
13429                                            break;
13430                                    }
13431                            }
13432                    }
13433    
13434                    if (list == null) {
13435                            StringBundler query = new StringBundler();
13436    
13437                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13438    
13439                            boolean conjunctionable = false;
13440    
13441                            if (conjunctionable) {
13442                                    query.append(WHERE_AND);
13443                            }
13444    
13445                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
13446    
13447                            conjunctionable = true;
13448    
13449                            if ((classNameIds == null) || (classNameIds.length > 0)) {
13450                                    if (conjunctionable) {
13451                                            query.append(WHERE_AND);
13452                                    }
13453    
13454                                    query.append(StringPool.OPEN_PARENTHESIS);
13455    
13456                                    for (int i = 0; i < classNameIds.length; i++) {
13457                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
13458    
13459                                            if ((i + 1) < classNameIds.length) {
13460                                                    query.append(WHERE_OR);
13461                                            }
13462                                    }
13463    
13464                                    query.append(StringPool.CLOSE_PARENTHESIS);
13465    
13466                                    conjunctionable = true;
13467                            }
13468    
13469                            if (conjunctionable) {
13470                                    query.append(WHERE_AND);
13471                            }
13472    
13473                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
13474    
13475                            conjunctionable = true;
13476    
13477                            if (orderByComparator != null) {
13478                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13479                                            orderByComparator);
13480                            }
13481    
13482                            else {
13483                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13484                            }
13485    
13486                            String sql = query.toString();
13487    
13488                            Session session = null;
13489    
13490                            try {
13491                                    session = openSession();
13492    
13493                                    Query q = session.createQuery(sql);
13494    
13495                                    QueryPos qPos = QueryPos.getInstance(q);
13496    
13497                                    qPos.add(userId);
13498    
13499                                    if (classNameIds != null) {
13500                                            qPos.add(classNameIds);
13501                                    }
13502    
13503                                    qPos.add(status);
13504    
13505                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
13506                                                    end);
13507                            }
13508                            catch (Exception e) {
13509                                    throw processException(e);
13510                            }
13511                            finally {
13512                                    if (list == null) {
13513                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
13514                                    }
13515                                    else {
13516                                            cacheResult(list);
13517    
13518                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
13519                                    }
13520    
13521                                    closeSession(session);
13522                            }
13523                    }
13524    
13525                    return list;
13526            }
13527    
13528            /**
13529             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
13530             *
13531             * @param classNameId the class name ID
13532             * @param classPK the class p k
13533             * @param status the status
13534             * @return the matching message-boards messages
13535             * @throws SystemException if a system exception occurred
13536             */
13537            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
13538                    int status) throws SystemException {
13539                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
13540                            QueryUtil.ALL_POS, null);
13541            }
13542    
13543            /**
13544             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
13545             *
13546             * <p>
13547             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13548             * </p>
13549             *
13550             * @param classNameId the class name ID
13551             * @param classPK the class p k
13552             * @param status the status
13553             * @param start the lower bound of the range of message-boards messages
13554             * @param end the upper bound of the range of message-boards messages (not inclusive)
13555             * @return the range of matching message-boards messages
13556             * @throws SystemException if a system exception occurred
13557             */
13558            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
13559                    int status, int start, int end) throws SystemException {
13560                    return findByC_C_S(classNameId, classPK, status, start, end, null);
13561            }
13562    
13563            /**
13564             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
13565             *
13566             * <p>
13567             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13568             * </p>
13569             *
13570             * @param classNameId the class name ID
13571             * @param classPK the class p k
13572             * @param status the status
13573             * @param start the lower bound of the range of message-boards messages
13574             * @param end the upper bound of the range of message-boards messages (not inclusive)
13575             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13576             * @return the ordered range of matching message-boards messages
13577             * @throws SystemException if a system exception occurred
13578             */
13579            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
13580                    int status, int start, int end, OrderByComparator orderByComparator)
13581                    throws SystemException {
13582                    FinderPath finderPath = null;
13583                    Object[] finderArgs = null;
13584    
13585                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13586                                    (orderByComparator == null)) {
13587                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
13588                            finderArgs = new Object[] { classNameId, classPK, status };
13589                    }
13590                    else {
13591                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
13592                            finderArgs = new Object[] {
13593                                            classNameId, classPK, status,
13594                                            
13595                                            start, end, orderByComparator
13596                                    };
13597                    }
13598    
13599                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
13600                                    finderArgs, this);
13601    
13602                    if ((list != null) && !list.isEmpty()) {
13603                            for (MBMessage mbMessage : list) {
13604                                    if ((classNameId != mbMessage.getClassNameId()) ||
13605                                                    (classPK != mbMessage.getClassPK()) ||
13606                                                    (status != mbMessage.getStatus())) {
13607                                            list = null;
13608    
13609                                            break;
13610                                    }
13611                            }
13612                    }
13613    
13614                    if (list == null) {
13615                            StringBundler query = null;
13616    
13617                            if (orderByComparator != null) {
13618                                    query = new StringBundler(5 +
13619                                                    (orderByComparator.getOrderByFields().length * 3));
13620                            }
13621                            else {
13622                                    query = new StringBundler(5);
13623                            }
13624    
13625                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13626    
13627                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
13628    
13629                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
13630    
13631                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
13632    
13633                            if (orderByComparator != null) {
13634                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13635                                            orderByComparator);
13636                            }
13637    
13638                            else {
13639                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13640                            }
13641    
13642                            String sql = query.toString();
13643    
13644                            Session session = null;
13645    
13646                            try {
13647                                    session = openSession();
13648    
13649                                    Query q = session.createQuery(sql);
13650    
13651                                    QueryPos qPos = QueryPos.getInstance(q);
13652    
13653                                    qPos.add(classNameId);
13654    
13655                                    qPos.add(classPK);
13656    
13657                                    qPos.add(status);
13658    
13659                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
13660                                                    end);
13661                            }
13662                            catch (Exception e) {
13663                                    throw processException(e);
13664                            }
13665                            finally {
13666                                    if (list == null) {
13667                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
13668                                    }
13669                                    else {
13670                                            cacheResult(list);
13671    
13672                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
13673                                    }
13674    
13675                                    closeSession(session);
13676                            }
13677                    }
13678    
13679                    return list;
13680            }
13681    
13682            /**
13683             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
13684             *
13685             * @param classNameId the class name ID
13686             * @param classPK the class p k
13687             * @param status the status
13688             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13689             * @return the first matching message-boards message
13690             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13691             * @throws SystemException if a system exception occurred
13692             */
13693            public MBMessage findByC_C_S_First(long classNameId, long classPK,
13694                    int status, OrderByComparator orderByComparator)
13695                    throws NoSuchMessageException, SystemException {
13696                    MBMessage mbMessage = fetchByC_C_S_First(classNameId, classPK, status,
13697                                    orderByComparator);
13698    
13699                    if (mbMessage != null) {
13700                            return mbMessage;
13701                    }
13702    
13703                    StringBundler msg = new StringBundler(8);
13704    
13705                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13706    
13707                    msg.append("classNameId=");
13708                    msg.append(classNameId);
13709    
13710                    msg.append(", classPK=");
13711                    msg.append(classPK);
13712    
13713                    msg.append(", status=");
13714                    msg.append(status);
13715    
13716                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13717    
13718                    throw new NoSuchMessageException(msg.toString());
13719            }
13720    
13721            /**
13722             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
13723             *
13724             * @param classNameId the class name ID
13725             * @param classPK the class p k
13726             * @param status the status
13727             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13728             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13729             * @throws SystemException if a system exception occurred
13730             */
13731            public MBMessage fetchByC_C_S_First(long classNameId, long classPK,
13732                    int status, OrderByComparator orderByComparator)
13733                    throws SystemException {
13734                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
13735                                    orderByComparator);
13736    
13737                    if (!list.isEmpty()) {
13738                            return list.get(0);
13739                    }
13740    
13741                    return null;
13742            }
13743    
13744            /**
13745             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
13746             *
13747             * @param classNameId the class name ID
13748             * @param classPK the class p k
13749             * @param status the status
13750             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13751             * @return the last matching message-boards message
13752             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13753             * @throws SystemException if a system exception occurred
13754             */
13755            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
13756                    int status, OrderByComparator orderByComparator)
13757                    throws NoSuchMessageException, SystemException {
13758                    MBMessage mbMessage = fetchByC_C_S_Last(classNameId, classPK, status,
13759                                    orderByComparator);
13760    
13761                    if (mbMessage != null) {
13762                            return mbMessage;
13763                    }
13764    
13765                    StringBundler msg = new StringBundler(8);
13766    
13767                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13768    
13769                    msg.append("classNameId=");
13770                    msg.append(classNameId);
13771    
13772                    msg.append(", classPK=");
13773                    msg.append(classPK);
13774    
13775                    msg.append(", status=");
13776                    msg.append(status);
13777    
13778                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13779    
13780                    throw new NoSuchMessageException(msg.toString());
13781            }
13782    
13783            /**
13784             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
13785             *
13786             * @param classNameId the class name ID
13787             * @param classPK the class p k
13788             * @param status the status
13789             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13790             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13791             * @throws SystemException if a system exception occurred
13792             */
13793            public MBMessage fetchByC_C_S_Last(long classNameId, long classPK,
13794                    int status, OrderByComparator orderByComparator)
13795                    throws SystemException {
13796                    int count = countByC_C_S(classNameId, classPK, status);
13797    
13798                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
13799                                    count - 1, count, orderByComparator);
13800    
13801                    if (!list.isEmpty()) {
13802                            return list.get(0);
13803                    }
13804    
13805                    return null;
13806            }
13807    
13808            /**
13809             * 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;.
13810             *
13811             * @param messageId the primary key of the current message-boards message
13812             * @param classNameId the class name ID
13813             * @param classPK the class p k
13814             * @param status the status
13815             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13816             * @return the previous, current, and next message-boards message
13817             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13818             * @throws SystemException if a system exception occurred
13819             */
13820            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
13821                    long classNameId, long classPK, int status,
13822                    OrderByComparator orderByComparator)
13823                    throws NoSuchMessageException, SystemException {
13824                    MBMessage mbMessage = findByPrimaryKey(messageId);
13825    
13826                    Session session = null;
13827    
13828                    try {
13829                            session = openSession();
13830    
13831                            MBMessage[] array = new MBMessageImpl[3];
13832    
13833                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
13834                                            classPK, status, orderByComparator, true);
13835    
13836                            array[1] = mbMessage;
13837    
13838                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
13839                                            classPK, status, orderByComparator, false);
13840    
13841                            return array;
13842                    }
13843                    catch (Exception e) {
13844                            throw processException(e);
13845                    }
13846                    finally {
13847                            closeSession(session);
13848                    }
13849            }
13850    
13851            protected MBMessage getByC_C_S_PrevAndNext(Session session,
13852                    MBMessage mbMessage, long classNameId, long classPK, int status,
13853                    OrderByComparator orderByComparator, boolean previous) {
13854                    StringBundler query = null;
13855    
13856                    if (orderByComparator != null) {
13857                            query = new StringBundler(6 +
13858                                            (orderByComparator.getOrderByFields().length * 6));
13859                    }
13860                    else {
13861                            query = new StringBundler(3);
13862                    }
13863    
13864                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13865    
13866                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
13867    
13868                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
13869    
13870                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
13871    
13872                    if (orderByComparator != null) {
13873                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13874    
13875                            if (orderByConditionFields.length > 0) {
13876                                    query.append(WHERE_AND);
13877                            }
13878    
13879                            for (int i = 0; i < orderByConditionFields.length; i++) {
13880                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13881                                    query.append(orderByConditionFields[i]);
13882    
13883                                    if ((i + 1) < orderByConditionFields.length) {
13884                                            if (orderByComparator.isAscending() ^ previous) {
13885                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13886                                            }
13887                                            else {
13888                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13889                                            }
13890                                    }
13891                                    else {
13892                                            if (orderByComparator.isAscending() ^ previous) {
13893                                                    query.append(WHERE_GREATER_THAN);
13894                                            }
13895                                            else {
13896                                                    query.append(WHERE_LESSER_THAN);
13897                                            }
13898                                    }
13899                            }
13900    
13901                            query.append(ORDER_BY_CLAUSE);
13902    
13903                            String[] orderByFields = orderByComparator.getOrderByFields();
13904    
13905                            for (int i = 0; i < orderByFields.length; i++) {
13906                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13907                                    query.append(orderByFields[i]);
13908    
13909                                    if ((i + 1) < orderByFields.length) {
13910                                            if (orderByComparator.isAscending() ^ previous) {
13911                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13912                                            }
13913                                            else {
13914                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13915                                            }
13916                                    }
13917                                    else {
13918                                            if (orderByComparator.isAscending() ^ previous) {
13919                                                    query.append(ORDER_BY_ASC);
13920                                            }
13921                                            else {
13922                                                    query.append(ORDER_BY_DESC);
13923                                            }
13924                                    }
13925                            }
13926                    }
13927    
13928                    else {
13929                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13930                    }
13931    
13932                    String sql = query.toString();
13933    
13934                    Query q = session.createQuery(sql);
13935    
13936                    q.setFirstResult(0);
13937                    q.setMaxResults(2);
13938    
13939                    QueryPos qPos = QueryPos.getInstance(q);
13940    
13941                    qPos.add(classNameId);
13942    
13943                    qPos.add(classPK);
13944    
13945                    qPos.add(status);
13946    
13947                    if (orderByComparator != null) {
13948                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13949    
13950                            for (Object value : values) {
13951                                    qPos.add(value);
13952                            }
13953                    }
13954    
13955                    List<MBMessage> list = q.list();
13956    
13957                    if (list.size() == 2) {
13958                            return list.get(1);
13959                    }
13960                    else {
13961                            return null;
13962                    }
13963            }
13964    
13965            /**
13966             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13967             *
13968             * @param groupId the group ID
13969             * @param categoryId the category ID
13970             * @param threadId the thread ID
13971             * @param answer the answer
13972             * @return the matching message-boards messages
13973             * @throws SystemException if a system exception occurred
13974             */
13975            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
13976                    long threadId, boolean answer) throws SystemException {
13977                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
13978                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13979            }
13980    
13981            /**
13982             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
13983             *
13984             * <p>
13985             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
13986             * </p>
13987             *
13988             * @param groupId the group ID
13989             * @param categoryId the category ID
13990             * @param threadId the thread ID
13991             * @param answer the answer
13992             * @param start the lower bound of the range of message-boards messages
13993             * @param end the upper bound of the range of message-boards messages (not inclusive)
13994             * @return the range of matching message-boards messages
13995             * @throws SystemException if a system exception occurred
13996             */
13997            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
13998                    long threadId, boolean answer, int start, int end)
13999                    throws SystemException {
14000                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
14001                            null);
14002            }
14003    
14004            /**
14005             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
14006             *
14007             * <p>
14008             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14009             * </p>
14010             *
14011             * @param groupId the group ID
14012             * @param categoryId the category ID
14013             * @param threadId the thread ID
14014             * @param answer the answer
14015             * @param start the lower bound of the range of message-boards messages
14016             * @param end the upper bound of the range of message-boards messages (not inclusive)
14017             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14018             * @return the ordered range of matching message-boards messages
14019             * @throws SystemException if a system exception occurred
14020             */
14021            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
14022                    long threadId, boolean answer, int start, int end,
14023                    OrderByComparator orderByComparator) throws SystemException {
14024                    FinderPath finderPath = null;
14025                    Object[] finderArgs = null;
14026    
14027                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14028                                    (orderByComparator == null)) {
14029                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
14030                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
14031                    }
14032                    else {
14033                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
14034                            finderArgs = new Object[] {
14035                                            groupId, categoryId, threadId, answer,
14036                                            
14037                                            start, end, orderByComparator
14038                                    };
14039                    }
14040    
14041                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
14042                                    finderArgs, this);
14043    
14044                    if ((list != null) && !list.isEmpty()) {
14045                            for (MBMessage mbMessage : list) {
14046                                    if ((groupId != mbMessage.getGroupId()) ||
14047                                                    (categoryId != mbMessage.getCategoryId()) ||
14048                                                    (threadId != mbMessage.getThreadId()) ||
14049                                                    (answer != mbMessage.getAnswer())) {
14050                                            list = null;
14051    
14052                                            break;
14053                                    }
14054                            }
14055                    }
14056    
14057                    if (list == null) {
14058                            StringBundler query = null;
14059    
14060                            if (orderByComparator != null) {
14061                                    query = new StringBundler(6 +
14062                                                    (orderByComparator.getOrderByFields().length * 3));
14063                            }
14064                            else {
14065                                    query = new StringBundler(6);
14066                            }
14067    
14068                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14069    
14070                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
14071    
14072                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
14073    
14074                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
14075    
14076                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
14077    
14078                            if (orderByComparator != null) {
14079                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14080                                            orderByComparator);
14081                            }
14082    
14083                            else {
14084                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14085                            }
14086    
14087                            String sql = query.toString();
14088    
14089                            Session session = null;
14090    
14091                            try {
14092                                    session = openSession();
14093    
14094                                    Query q = session.createQuery(sql);
14095    
14096                                    QueryPos qPos = QueryPos.getInstance(q);
14097    
14098                                    qPos.add(groupId);
14099    
14100                                    qPos.add(categoryId);
14101    
14102                                    qPos.add(threadId);
14103    
14104                                    qPos.add(answer);
14105    
14106                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
14107                                                    end);
14108                            }
14109                            catch (Exception e) {
14110                                    throw processException(e);
14111                            }
14112                            finally {
14113                                    if (list == null) {
14114                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
14115                                    }
14116                                    else {
14117                                            cacheResult(list);
14118    
14119                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
14120                                    }
14121    
14122                                    closeSession(session);
14123                            }
14124                    }
14125    
14126                    return list;
14127            }
14128    
14129            /**
14130             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
14131             *
14132             * @param groupId the group ID
14133             * @param categoryId the category ID
14134             * @param threadId the thread ID
14135             * @param answer the answer
14136             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14137             * @return the first matching message-boards message
14138             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14139             * @throws SystemException if a system exception occurred
14140             */
14141            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
14142                    long threadId, boolean answer, OrderByComparator orderByComparator)
14143                    throws NoSuchMessageException, SystemException {
14144                    MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
14145                                    threadId, answer, orderByComparator);
14146    
14147                    if (mbMessage != null) {
14148                            return mbMessage;
14149                    }
14150    
14151                    StringBundler msg = new StringBundler(10);
14152    
14153                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14154    
14155                    msg.append("groupId=");
14156                    msg.append(groupId);
14157    
14158                    msg.append(", categoryId=");
14159                    msg.append(categoryId);
14160    
14161                    msg.append(", threadId=");
14162                    msg.append(threadId);
14163    
14164                    msg.append(", answer=");
14165                    msg.append(answer);
14166    
14167                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14168    
14169                    throw new NoSuchMessageException(msg.toString());
14170            }
14171    
14172            /**
14173             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
14174             *
14175             * @param groupId the group ID
14176             * @param categoryId the category ID
14177             * @param threadId the thread ID
14178             * @param answer the answer
14179             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14180             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14181             * @throws SystemException if a system exception occurred
14182             */
14183            public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
14184                    long threadId, boolean answer, OrderByComparator orderByComparator)
14185                    throws SystemException {
14186                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
14187                                    answer, 0, 1, orderByComparator);
14188    
14189                    if (!list.isEmpty()) {
14190                            return list.get(0);
14191                    }
14192    
14193                    return null;
14194            }
14195    
14196            /**
14197             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
14198             *
14199             * @param groupId the group ID
14200             * @param categoryId the category ID
14201             * @param threadId the thread ID
14202             * @param answer the answer
14203             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14204             * @return the last matching message-boards message
14205             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14206             * @throws SystemException if a system exception occurred
14207             */
14208            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
14209                    long threadId, boolean answer, OrderByComparator orderByComparator)
14210                    throws NoSuchMessageException, SystemException {
14211                    MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
14212                                    threadId, answer, orderByComparator);
14213    
14214                    if (mbMessage != null) {
14215                            return mbMessage;
14216                    }
14217    
14218                    StringBundler msg = new StringBundler(10);
14219    
14220                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14221    
14222                    msg.append("groupId=");
14223                    msg.append(groupId);
14224    
14225                    msg.append(", categoryId=");
14226                    msg.append(categoryId);
14227    
14228                    msg.append(", threadId=");
14229                    msg.append(threadId);
14230    
14231                    msg.append(", answer=");
14232                    msg.append(answer);
14233    
14234                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14235    
14236                    throw new NoSuchMessageException(msg.toString());
14237            }
14238    
14239            /**
14240             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
14241             *
14242             * @param groupId the group ID
14243             * @param categoryId the category ID
14244             * @param threadId the thread ID
14245             * @param answer the answer
14246             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14247             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14248             * @throws SystemException if a system exception occurred
14249             */
14250            public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
14251                    long threadId, boolean answer, OrderByComparator orderByComparator)
14252                    throws SystemException {
14253                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
14254    
14255                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
14256                                    answer, count - 1, count, orderByComparator);
14257    
14258                    if (!list.isEmpty()) {
14259                            return list.get(0);
14260                    }
14261    
14262                    return null;
14263            }
14264    
14265            /**
14266             * 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;.
14267             *
14268             * @param messageId the primary key of the current message-boards message
14269             * @param groupId the group ID
14270             * @param categoryId the category ID
14271             * @param threadId the thread ID
14272             * @param answer the answer
14273             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14274             * @return the previous, current, and next message-boards message
14275             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14276             * @throws SystemException if a system exception occurred
14277             */
14278            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
14279                    long categoryId, long threadId, boolean answer,
14280                    OrderByComparator orderByComparator)
14281                    throws NoSuchMessageException, SystemException {
14282                    MBMessage mbMessage = findByPrimaryKey(messageId);
14283    
14284                    Session session = null;
14285    
14286                    try {
14287                            session = openSession();
14288    
14289                            MBMessage[] array = new MBMessageImpl[3];
14290    
14291                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
14292                                            categoryId, threadId, answer, orderByComparator, true);
14293    
14294                            array[1] = mbMessage;
14295    
14296                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
14297                                            categoryId, threadId, answer, orderByComparator, false);
14298    
14299                            return array;
14300                    }
14301                    catch (Exception e) {
14302                            throw processException(e);
14303                    }
14304                    finally {
14305                            closeSession(session);
14306                    }
14307            }
14308    
14309            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
14310                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
14311                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
14312                    StringBundler query = null;
14313    
14314                    if (orderByComparator != null) {
14315                            query = new StringBundler(6 +
14316                                            (orderByComparator.getOrderByFields().length * 6));
14317                    }
14318                    else {
14319                            query = new StringBundler(3);
14320                    }
14321    
14322                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14323    
14324                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
14325    
14326                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
14327    
14328                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
14329    
14330                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
14331    
14332                    if (orderByComparator != null) {
14333                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14334    
14335                            if (orderByConditionFields.length > 0) {
14336                                    query.append(WHERE_AND);
14337                            }
14338    
14339                            for (int i = 0; i < orderByConditionFields.length; i++) {
14340                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14341                                    query.append(orderByConditionFields[i]);
14342    
14343                                    if ((i + 1) < orderByConditionFields.length) {
14344                                            if (orderByComparator.isAscending() ^ previous) {
14345                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14346                                            }
14347                                            else {
14348                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14349                                            }
14350                                    }
14351                                    else {
14352                                            if (orderByComparator.isAscending() ^ previous) {
14353                                                    query.append(WHERE_GREATER_THAN);
14354                                            }
14355                                            else {
14356                                                    query.append(WHERE_LESSER_THAN);
14357                                            }
14358                                    }
14359                            }
14360    
14361                            query.append(ORDER_BY_CLAUSE);
14362    
14363                            String[] orderByFields = orderByComparator.getOrderByFields();
14364    
14365                            for (int i = 0; i < orderByFields.length; i++) {
14366                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14367                                    query.append(orderByFields[i]);
14368    
14369                                    if ((i + 1) < orderByFields.length) {
14370                                            if (orderByComparator.isAscending() ^ previous) {
14371                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14372                                            }
14373                                            else {
14374                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14375                                            }
14376                                    }
14377                                    else {
14378                                            if (orderByComparator.isAscending() ^ previous) {
14379                                                    query.append(ORDER_BY_ASC);
14380                                            }
14381                                            else {
14382                                                    query.append(ORDER_BY_DESC);
14383                                            }
14384                                    }
14385                            }
14386                    }
14387    
14388                    else {
14389                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14390                    }
14391    
14392                    String sql = query.toString();
14393    
14394                    Query q = session.createQuery(sql);
14395    
14396                    q.setFirstResult(0);
14397                    q.setMaxResults(2);
14398    
14399                    QueryPos qPos = QueryPos.getInstance(q);
14400    
14401                    qPos.add(groupId);
14402    
14403                    qPos.add(categoryId);
14404    
14405                    qPos.add(threadId);
14406    
14407                    qPos.add(answer);
14408    
14409                    if (orderByComparator != null) {
14410                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14411    
14412                            for (Object value : values) {
14413                                    qPos.add(value);
14414                            }
14415                    }
14416    
14417                    List<MBMessage> list = q.list();
14418    
14419                    if (list.size() == 2) {
14420                            return list.get(1);
14421                    }
14422                    else {
14423                            return null;
14424                    }
14425            }
14426    
14427            /**
14428             * 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;.
14429             *
14430             * @param groupId the group ID
14431             * @param categoryId the category ID
14432             * @param threadId the thread ID
14433             * @param answer the answer
14434             * @return the matching message-boards messages that the user has permission to view
14435             * @throws SystemException if a system exception occurred
14436             */
14437            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
14438                    long threadId, boolean answer) throws SystemException {
14439                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
14440                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14441            }
14442    
14443            /**
14444             * 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;.
14445             *
14446             * <p>
14447             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14448             * </p>
14449             *
14450             * @param groupId the group ID
14451             * @param categoryId the category ID
14452             * @param threadId the thread ID
14453             * @param answer the answer
14454             * @param start the lower bound of the range of message-boards messages
14455             * @param end the upper bound of the range of message-boards messages (not inclusive)
14456             * @return the range of matching message-boards messages that the user has permission to view
14457             * @throws SystemException if a system exception occurred
14458             */
14459            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
14460                    long threadId, boolean answer, int start, int end)
14461                    throws SystemException {
14462                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
14463                            start, end, null);
14464            }
14465    
14466            /**
14467             * 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;.
14468             *
14469             * <p>
14470             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14471             * </p>
14472             *
14473             * @param groupId the group ID
14474             * @param categoryId the category ID
14475             * @param threadId the thread ID
14476             * @param answer the answer
14477             * @param start the lower bound of the range of message-boards messages
14478             * @param end the upper bound of the range of message-boards messages (not inclusive)
14479             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14480             * @return the ordered range of matching message-boards messages that the user has permission to view
14481             * @throws SystemException if a system exception occurred
14482             */
14483            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
14484                    long threadId, boolean answer, int start, int end,
14485                    OrderByComparator orderByComparator) throws SystemException {
14486                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14487                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
14488                                    end, orderByComparator);
14489                    }
14490    
14491                    StringBundler query = null;
14492    
14493                    if (orderByComparator != null) {
14494                            query = new StringBundler(6 +
14495                                            (orderByComparator.getOrderByFields().length * 3));
14496                    }
14497                    else {
14498                            query = new StringBundler(6);
14499                    }
14500    
14501                    if (getDB().isSupportsInlineDistinct()) {
14502                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
14503                    }
14504                    else {
14505                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
14506                    }
14507    
14508                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
14509    
14510                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
14511    
14512                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
14513    
14514                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
14515    
14516                    if (!getDB().isSupportsInlineDistinct()) {
14517                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
14518                    }
14519    
14520                    if (orderByComparator != null) {
14521                            if (getDB().isSupportsInlineDistinct()) {
14522                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14523                                            orderByComparator);
14524                            }
14525                            else {
14526                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
14527                                            orderByComparator);
14528                            }
14529                    }
14530    
14531                    else {
14532                            if (getDB().isSupportsInlineDistinct()) {
14533                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14534                            }
14535                            else {
14536                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
14537                            }
14538                    }
14539    
14540                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14541                                    MBMessage.class.getName(),
14542                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14543    
14544                    Session session = null;
14545    
14546                    try {
14547                            session = openSession();
14548    
14549                            SQLQuery q = session.createSQLQuery(sql);
14550    
14551                            if (getDB().isSupportsInlineDistinct()) {
14552                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
14553                            }
14554                            else {
14555                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
14556                            }
14557    
14558                            QueryPos qPos = QueryPos.getInstance(q);
14559    
14560                            qPos.add(groupId);
14561    
14562                            qPos.add(categoryId);
14563    
14564                            qPos.add(threadId);
14565    
14566                            qPos.add(answer);
14567    
14568                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
14569                    }
14570                    catch (Exception e) {
14571                            throw processException(e);
14572                    }
14573                    finally {
14574                            closeSession(session);
14575                    }
14576            }
14577    
14578            /**
14579             * 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;.
14580             *
14581             * @param messageId the primary key of the current message-boards message
14582             * @param groupId the group ID
14583             * @param categoryId the category ID
14584             * @param threadId the thread ID
14585             * @param answer the answer
14586             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14587             * @return the previous, current, and next message-boards message
14588             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14589             * @throws SystemException if a system exception occurred
14590             */
14591            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
14592                    long groupId, long categoryId, long threadId, boolean answer,
14593                    OrderByComparator orderByComparator)
14594                    throws NoSuchMessageException, SystemException {
14595                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14596                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
14597                                    threadId, answer, orderByComparator);
14598                    }
14599    
14600                    MBMessage mbMessage = findByPrimaryKey(messageId);
14601    
14602                    Session session = null;
14603    
14604                    try {
14605                            session = openSession();
14606    
14607                            MBMessage[] array = new MBMessageImpl[3];
14608    
14609                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
14610                                            groupId, categoryId, threadId, answer, orderByComparator,
14611                                            true);
14612    
14613                            array[1] = mbMessage;
14614    
14615                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
14616                                            groupId, categoryId, threadId, answer, orderByComparator,
14617                                            false);
14618    
14619                            return array;
14620                    }
14621                    catch (Exception e) {
14622                            throw processException(e);
14623                    }
14624                    finally {
14625                            closeSession(session);
14626                    }
14627            }
14628    
14629            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
14630                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
14631                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
14632                    StringBundler query = null;
14633    
14634                    if (orderByComparator != null) {
14635                            query = new StringBundler(6 +
14636                                            (orderByComparator.getOrderByFields().length * 6));
14637                    }
14638                    else {
14639                            query = new StringBundler(3);
14640                    }
14641    
14642                    if (getDB().isSupportsInlineDistinct()) {
14643                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
14644                    }
14645                    else {
14646                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
14647                    }
14648    
14649                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
14650    
14651                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
14652    
14653                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
14654    
14655                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
14656    
14657                    if (!getDB().isSupportsInlineDistinct()) {
14658                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
14659                    }
14660    
14661                    if (orderByComparator != null) {
14662                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14663    
14664                            if (orderByConditionFields.length > 0) {
14665                                    query.append(WHERE_AND);
14666                            }
14667    
14668                            for (int i = 0; i < orderByConditionFields.length; i++) {
14669                                    if (getDB().isSupportsInlineDistinct()) {
14670                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14671                                    }
14672                                    else {
14673                                            query.append(_ORDER_BY_ENTITY_TABLE);
14674                                    }
14675    
14676                                    query.append(orderByConditionFields[i]);
14677    
14678                                    if ((i + 1) < orderByConditionFields.length) {
14679                                            if (orderByComparator.isAscending() ^ previous) {
14680                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14681                                            }
14682                                            else {
14683                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14684                                            }
14685                                    }
14686                                    else {
14687                                            if (orderByComparator.isAscending() ^ previous) {
14688                                                    query.append(WHERE_GREATER_THAN);
14689                                            }
14690                                            else {
14691                                                    query.append(WHERE_LESSER_THAN);
14692                                            }
14693                                    }
14694                            }
14695    
14696                            query.append(ORDER_BY_CLAUSE);
14697    
14698                            String[] orderByFields = orderByComparator.getOrderByFields();
14699    
14700                            for (int i = 0; i < orderByFields.length; i++) {
14701                                    if (getDB().isSupportsInlineDistinct()) {
14702                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14703                                    }
14704                                    else {
14705                                            query.append(_ORDER_BY_ENTITY_TABLE);
14706                                    }
14707    
14708                                    query.append(orderByFields[i]);
14709    
14710                                    if ((i + 1) < orderByFields.length) {
14711                                            if (orderByComparator.isAscending() ^ previous) {
14712                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14713                                            }
14714                                            else {
14715                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14716                                            }
14717                                    }
14718                                    else {
14719                                            if (orderByComparator.isAscending() ^ previous) {
14720                                                    query.append(ORDER_BY_ASC);
14721                                            }
14722                                            else {
14723                                                    query.append(ORDER_BY_DESC);
14724                                            }
14725                                    }
14726                            }
14727                    }
14728    
14729                    else {
14730                            if (getDB().isSupportsInlineDistinct()) {
14731                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14732                            }
14733                            else {
14734                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
14735                            }
14736                    }
14737    
14738                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14739                                    MBMessage.class.getName(),
14740                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14741    
14742                    SQLQuery q = session.createSQLQuery(sql);
14743    
14744                    q.setFirstResult(0);
14745                    q.setMaxResults(2);
14746    
14747                    if (getDB().isSupportsInlineDistinct()) {
14748                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
14749                    }
14750                    else {
14751                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
14752                    }
14753    
14754                    QueryPos qPos = QueryPos.getInstance(q);
14755    
14756                    qPos.add(groupId);
14757    
14758                    qPos.add(categoryId);
14759    
14760                    qPos.add(threadId);
14761    
14762                    qPos.add(answer);
14763    
14764                    if (orderByComparator != null) {
14765                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14766    
14767                            for (Object value : values) {
14768                                    qPos.add(value);
14769                            }
14770                    }
14771    
14772                    List<MBMessage> list = q.list();
14773    
14774                    if (list.size() == 2) {
14775                            return list.get(1);
14776                    }
14777                    else {
14778                            return null;
14779                    }
14780            }
14781    
14782            /**
14783             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14784             *
14785             * @param groupId the group ID
14786             * @param categoryId the category ID
14787             * @param threadId the thread ID
14788             * @param status the status
14789             * @return the matching message-boards messages
14790             * @throws SystemException if a system exception occurred
14791             */
14792            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
14793                    long threadId, int status) throws SystemException {
14794                    return findByG_C_T_S(groupId, categoryId, threadId, status,
14795                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
14796            }
14797    
14798            /**
14799             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14800             *
14801             * <p>
14802             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14803             * </p>
14804             *
14805             * @param groupId the group ID
14806             * @param categoryId the category ID
14807             * @param threadId the thread ID
14808             * @param status the status
14809             * @param start the lower bound of the range of message-boards messages
14810             * @param end the upper bound of the range of message-boards messages (not inclusive)
14811             * @return the range of matching message-boards messages
14812             * @throws SystemException if a system exception occurred
14813             */
14814            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
14815                    long threadId, int status, int start, int end)
14816                    throws SystemException {
14817                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
14818                            null);
14819            }
14820    
14821            /**
14822             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14823             *
14824             * <p>
14825             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
14826             * </p>
14827             *
14828             * @param groupId the group ID
14829             * @param categoryId the category ID
14830             * @param threadId the thread ID
14831             * @param status the status
14832             * @param start the lower bound of the range of message-boards messages
14833             * @param end the upper bound of the range of message-boards messages (not inclusive)
14834             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14835             * @return the ordered range of matching message-boards messages
14836             * @throws SystemException if a system exception occurred
14837             */
14838            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
14839                    long threadId, int status, int start, int end,
14840                    OrderByComparator orderByComparator) throws SystemException {
14841                    FinderPath finderPath = null;
14842                    Object[] finderArgs = null;
14843    
14844                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14845                                    (orderByComparator == null)) {
14846                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
14847                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
14848                    }
14849                    else {
14850                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
14851                            finderArgs = new Object[] {
14852                                            groupId, categoryId, threadId, status,
14853                                            
14854                                            start, end, orderByComparator
14855                                    };
14856                    }
14857    
14858                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
14859                                    finderArgs, this);
14860    
14861                    if ((list != null) && !list.isEmpty()) {
14862                            for (MBMessage mbMessage : list) {
14863                                    if ((groupId != mbMessage.getGroupId()) ||
14864                                                    (categoryId != mbMessage.getCategoryId()) ||
14865                                                    (threadId != mbMessage.getThreadId()) ||
14866                                                    (status != mbMessage.getStatus())) {
14867                                            list = null;
14868    
14869                                            break;
14870                                    }
14871                            }
14872                    }
14873    
14874                    if (list == null) {
14875                            StringBundler query = null;
14876    
14877                            if (orderByComparator != null) {
14878                                    query = new StringBundler(6 +
14879                                                    (orderByComparator.getOrderByFields().length * 3));
14880                            }
14881                            else {
14882                                    query = new StringBundler(6);
14883                            }
14884    
14885                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14886    
14887                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
14888    
14889                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
14890    
14891                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
14892    
14893                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
14894    
14895                            if (orderByComparator != null) {
14896                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14897                                            orderByComparator);
14898                            }
14899    
14900                            else {
14901                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14902                            }
14903    
14904                            String sql = query.toString();
14905    
14906                            Session session = null;
14907    
14908                            try {
14909                                    session = openSession();
14910    
14911                                    Query q = session.createQuery(sql);
14912    
14913                                    QueryPos qPos = QueryPos.getInstance(q);
14914    
14915                                    qPos.add(groupId);
14916    
14917                                    qPos.add(categoryId);
14918    
14919                                    qPos.add(threadId);
14920    
14921                                    qPos.add(status);
14922    
14923                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
14924                                                    end);
14925                            }
14926                            catch (Exception e) {
14927                                    throw processException(e);
14928                            }
14929                            finally {
14930                                    if (list == null) {
14931                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
14932                                    }
14933                                    else {
14934                                            cacheResult(list);
14935    
14936                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
14937                                    }
14938    
14939                                    closeSession(session);
14940                            }
14941                    }
14942    
14943                    return list;
14944            }
14945    
14946            /**
14947             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14948             *
14949             * @param groupId the group ID
14950             * @param categoryId the category ID
14951             * @param threadId the thread ID
14952             * @param status the status
14953             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14954             * @return the first matching message-boards message
14955             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14956             * @throws SystemException if a system exception occurred
14957             */
14958            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
14959                    long threadId, int status, OrderByComparator orderByComparator)
14960                    throws NoSuchMessageException, SystemException {
14961                    MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
14962                                    threadId, status, orderByComparator);
14963    
14964                    if (mbMessage != null) {
14965                            return mbMessage;
14966                    }
14967    
14968                    StringBundler msg = new StringBundler(10);
14969    
14970                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14971    
14972                    msg.append("groupId=");
14973                    msg.append(groupId);
14974    
14975                    msg.append(", categoryId=");
14976                    msg.append(categoryId);
14977    
14978                    msg.append(", threadId=");
14979                    msg.append(threadId);
14980    
14981                    msg.append(", status=");
14982                    msg.append(status);
14983    
14984                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14985    
14986                    throw new NoSuchMessageException(msg.toString());
14987            }
14988    
14989            /**
14990             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
14991             *
14992             * @param groupId the group ID
14993             * @param categoryId the category ID
14994             * @param threadId the thread ID
14995             * @param status the status
14996             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14997             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14998             * @throws SystemException if a system exception occurred
14999             */
15000            public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
15001                    long threadId, int status, OrderByComparator orderByComparator)
15002                    throws SystemException {
15003                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
15004                                    status, 0, 1, orderByComparator);
15005    
15006                    if (!list.isEmpty()) {
15007                            return list.get(0);
15008                    }
15009    
15010                    return null;
15011            }
15012    
15013            /**
15014             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
15015             *
15016             * @param groupId the group ID
15017             * @param categoryId the category ID
15018             * @param threadId the thread ID
15019             * @param status the status
15020             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15021             * @return the last matching message-boards message
15022             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15023             * @throws SystemException if a system exception occurred
15024             */
15025            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
15026                    long threadId, int status, OrderByComparator orderByComparator)
15027                    throws NoSuchMessageException, SystemException {
15028                    MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
15029                                    threadId, status, orderByComparator);
15030    
15031                    if (mbMessage != null) {
15032                            return mbMessage;
15033                    }
15034    
15035                    StringBundler msg = new StringBundler(10);
15036    
15037                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15038    
15039                    msg.append("groupId=");
15040                    msg.append(groupId);
15041    
15042                    msg.append(", categoryId=");
15043                    msg.append(categoryId);
15044    
15045                    msg.append(", threadId=");
15046                    msg.append(threadId);
15047    
15048                    msg.append(", status=");
15049                    msg.append(status);
15050    
15051                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15052    
15053                    throw new NoSuchMessageException(msg.toString());
15054            }
15055    
15056            /**
15057             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
15058             *
15059             * @param groupId the group ID
15060             * @param categoryId the category ID
15061             * @param threadId the thread ID
15062             * @param status the status
15063             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15064             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15065             * @throws SystemException if a system exception occurred
15066             */
15067            public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
15068                    long threadId, int status, OrderByComparator orderByComparator)
15069                    throws SystemException {
15070                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
15071    
15072                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
15073                                    status, count - 1, count, orderByComparator);
15074    
15075                    if (!list.isEmpty()) {
15076                            return list.get(0);
15077                    }
15078    
15079                    return null;
15080            }
15081    
15082            /**
15083             * 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;.
15084             *
15085             * @param messageId the primary key of the current message-boards message
15086             * @param groupId the group ID
15087             * @param categoryId the category ID
15088             * @param threadId the thread ID
15089             * @param status the status
15090             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15091             * @return the previous, current, and next message-boards message
15092             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
15093             * @throws SystemException if a system exception occurred
15094             */
15095            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
15096                    long categoryId, long threadId, int status,
15097                    OrderByComparator orderByComparator)
15098                    throws NoSuchMessageException, SystemException {
15099                    MBMessage mbMessage = findByPrimaryKey(messageId);
15100    
15101                    Session session = null;
15102    
15103                    try {
15104                            session = openSession();
15105    
15106                            MBMessage[] array = new MBMessageImpl[3];
15107    
15108                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
15109                                            categoryId, threadId, status, orderByComparator, true);
15110    
15111                            array[1] = mbMessage;
15112    
15113                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
15114                                            categoryId, threadId, status, orderByComparator, false);
15115    
15116                            return array;
15117                    }
15118                    catch (Exception e) {
15119                            throw processException(e);
15120                    }
15121                    finally {
15122                            closeSession(session);
15123                    }
15124            }
15125    
15126            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
15127                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
15128                    int status, OrderByComparator orderByComparator, boolean previous) {
15129                    StringBundler query = null;
15130    
15131                    if (orderByComparator != null) {
15132                            query = new StringBundler(6 +
15133                                            (orderByComparator.getOrderByFields().length * 6));
15134                    }
15135                    else {
15136                            query = new StringBundler(3);
15137                    }
15138    
15139                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15140    
15141                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
15142    
15143                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
15144    
15145                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
15146    
15147                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
15148    
15149                    if (orderByComparator != null) {
15150                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15151    
15152                            if (orderByConditionFields.length > 0) {
15153                                    query.append(WHERE_AND);
15154                            }
15155    
15156                            for (int i = 0; i < orderByConditionFields.length; i++) {
15157                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15158                                    query.append(orderByConditionFields[i]);
15159    
15160                                    if ((i + 1) < orderByConditionFields.length) {
15161                                            if (orderByComparator.isAscending() ^ previous) {
15162                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15163                                            }
15164                                            else {
15165                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15166                                            }
15167                                    }
15168                                    else {
15169                                            if (orderByComparator.isAscending() ^ previous) {
15170                                                    query.append(WHERE_GREATER_THAN);
15171                                            }
15172                                            else {
15173                                                    query.append(WHERE_LESSER_THAN);
15174                                            }
15175                                    }
15176                            }
15177    
15178                            query.append(ORDER_BY_CLAUSE);
15179    
15180                            String[] orderByFields = orderByComparator.getOrderByFields();
15181    
15182                            for (int i = 0; i < orderByFields.length; i++) {
15183                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15184                                    query.append(orderByFields[i]);
15185    
15186                                    if ((i + 1) < orderByFields.length) {
15187                                            if (orderByComparator.isAscending() ^ previous) {
15188                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15189                                            }
15190                                            else {
15191                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15192                                            }
15193                                    }
15194                                    else {
15195                                            if (orderByComparator.isAscending() ^ previous) {
15196                                                    query.append(ORDER_BY_ASC);
15197                                            }
15198                                            else {
15199                                                    query.append(ORDER_BY_DESC);
15200                                            }
15201                                    }
15202                            }
15203                    }
15204    
15205                    else {
15206                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15207                    }
15208    
15209                    String sql = query.toString();
15210    
15211                    Query q = session.createQuery(sql);
15212    
15213                    q.setFirstResult(0);
15214                    q.setMaxResults(2);
15215    
15216                    QueryPos qPos = QueryPos.getInstance(q);
15217    
15218                    qPos.add(groupId);
15219    
15220                    qPos.add(categoryId);
15221    
15222                    qPos.add(threadId);
15223    
15224                    qPos.add(status);
15225    
15226                    if (orderByComparator != null) {
15227                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15228    
15229                            for (Object value : values) {
15230                                    qPos.add(value);
15231                            }
15232                    }
15233    
15234                    List<MBMessage> list = q.list();
15235    
15236                    if (list.size() == 2) {
15237                            return list.get(1);
15238                    }
15239                    else {
15240                            return null;
15241                    }
15242            }
15243    
15244            /**
15245             * 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;.
15246             *
15247             * @param groupId the group ID
15248             * @param categoryId the category ID
15249             * @param threadId the thread ID
15250             * @param status the status
15251             * @return the matching message-boards messages that the user has permission to view
15252             * @throws SystemException if a system exception occurred
15253             */
15254            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
15255                    long threadId, int status) throws SystemException {
15256                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
15257                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15258            }
15259    
15260            /**
15261             * 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;.
15262             *
15263             * <p>
15264             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
15265             * </p>
15266             *
15267             * @param groupId the group ID
15268             * @param categoryId the category ID
15269             * @param threadId the thread ID
15270             * @param status the status
15271             * @param start the lower bound of the range of message-boards messages
15272             * @param end the upper bound of the range of message-boards messages (not inclusive)
15273             * @return the range of matching message-boards messages that the user has permission to view
15274             * @throws SystemException if a system exception occurred
15275             */
15276            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
15277                    long threadId, int status, int start, int end)
15278                    throws SystemException {
15279                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
15280                            start, end, null);
15281            }
15282    
15283            /**
15284             * 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;.
15285             *
15286             * <p>
15287             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
15288             * </p>
15289             *
15290             * @param groupId the group ID
15291             * @param categoryId the category ID
15292             * @param threadId the thread ID
15293             * @param status the status
15294             * @param start the lower bound of the range of message-boards messages
15295             * @param end the upper bound of the range of message-boards messages (not inclusive)
15296             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15297             * @return the ordered range of matching message-boards messages that the user has permission to view
15298             * @throws SystemException if a system exception occurred
15299             */
15300            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
15301                    long threadId, int status, int start, int end,
15302                    OrderByComparator orderByComparator) throws SystemException {
15303                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15304                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
15305                                    end, orderByComparator);
15306                    }
15307    
15308                    StringBundler query = null;
15309    
15310                    if (orderByComparator != null) {
15311                            query = new StringBundler(6 +
15312                                            (orderByComparator.getOrderByFields().length * 3));
15313                    }
15314                    else {
15315                            query = new StringBundler(6);
15316                    }
15317    
15318                    if (getDB().isSupportsInlineDistinct()) {
15319                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
15320                    }
15321                    else {
15322                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
15323                    }
15324    
15325                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
15326    
15327                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
15328    
15329                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
15330    
15331                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
15332    
15333                    if (!getDB().isSupportsInlineDistinct()) {
15334                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
15335                    }
15336    
15337                    if (orderByComparator != null) {
15338                            if (getDB().isSupportsInlineDistinct()) {
15339                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15340                                            orderByComparator);
15341                            }
15342                            else {
15343                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
15344                                            orderByComparator);
15345                            }
15346                    }
15347    
15348                    else {
15349                            if (getDB().isSupportsInlineDistinct()) {
15350                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15351                            }
15352                            else {
15353                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
15354                            }
15355                    }
15356    
15357                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15358                                    MBMessage.class.getName(),
15359                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15360    
15361                    Session session = null;
15362    
15363                    try {
15364                            session = openSession();
15365    
15366                            SQLQuery q = session.createSQLQuery(sql);
15367    
15368                            if (getDB().isSupportsInlineDistinct()) {
15369                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
15370                            }
15371                            else {
15372                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
15373                            }
15374    
15375                            QueryPos qPos = QueryPos.getInstance(q);
15376    
15377                            qPos.add(groupId);
15378    
15379                            qPos.add(categoryId);
15380    
15381                            qPos.add(threadId);
15382    
15383                            qPos.add(status);
15384    
15385                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
15386                    }
15387                    catch (Exception e) {
15388                            throw processException(e);
15389                    }
15390                    finally {
15391                            closeSession(session);
15392                    }
15393            }
15394    
15395            /**
15396             * 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;.
15397             *
15398             * @param messageId the primary key of the current message-boards message
15399             * @param groupId the group ID
15400             * @param categoryId the category ID
15401             * @param threadId the thread ID
15402             * @param status the status
15403             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15404             * @return the previous, current, and next message-boards message
15405             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
15406             * @throws SystemException if a system exception occurred
15407             */
15408            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
15409                    long groupId, long categoryId, long threadId, int status,
15410                    OrderByComparator orderByComparator)
15411                    throws NoSuchMessageException, SystemException {
15412                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
15413                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
15414                                    threadId, status, orderByComparator);
15415                    }
15416    
15417                    MBMessage mbMessage = findByPrimaryKey(messageId);
15418    
15419                    Session session = null;
15420    
15421                    try {
15422                            session = openSession();
15423    
15424                            MBMessage[] array = new MBMessageImpl[3];
15425    
15426                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
15427                                            groupId, categoryId, threadId, status, orderByComparator,
15428                                            true);
15429    
15430                            array[1] = mbMessage;
15431    
15432                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
15433                                            groupId, categoryId, threadId, status, orderByComparator,
15434                                            false);
15435    
15436                            return array;
15437                    }
15438                    catch (Exception e) {
15439                            throw processException(e);
15440                    }
15441                    finally {
15442                            closeSession(session);
15443                    }
15444            }
15445    
15446            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
15447                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
15448                    int status, OrderByComparator orderByComparator, boolean previous) {
15449                    StringBundler query = null;
15450    
15451                    if (orderByComparator != null) {
15452                            query = new StringBundler(6 +
15453                                            (orderByComparator.getOrderByFields().length * 6));
15454                    }
15455                    else {
15456                            query = new StringBundler(3);
15457                    }
15458    
15459                    if (getDB().isSupportsInlineDistinct()) {
15460                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
15461                    }
15462                    else {
15463                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
15464                    }
15465    
15466                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
15467    
15468                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
15469    
15470                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
15471    
15472                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
15473    
15474                    if (!getDB().isSupportsInlineDistinct()) {
15475                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
15476                    }
15477    
15478                    if (orderByComparator != null) {
15479                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15480    
15481                            if (orderByConditionFields.length > 0) {
15482                                    query.append(WHERE_AND);
15483                            }
15484    
15485                            for (int i = 0; i < orderByConditionFields.length; i++) {
15486                                    if (getDB().isSupportsInlineDistinct()) {
15487                                            query.append(_ORDER_BY_ENTITY_ALIAS);
15488                                    }
15489                                    else {
15490                                            query.append(_ORDER_BY_ENTITY_TABLE);
15491                                    }
15492    
15493                                    query.append(orderByConditionFields[i]);
15494    
15495                                    if ((i + 1) < orderByConditionFields.length) {
15496                                            if (orderByComparator.isAscending() ^ previous) {
15497                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15498                                            }
15499                                            else {
15500                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15501                                            }
15502                                    }
15503                                    else {
15504                                            if (orderByComparator.isAscending() ^ previous) {
15505                                                    query.append(WHERE_GREATER_THAN);
15506                                            }
15507                                            else {
15508                                                    query.append(WHERE_LESSER_THAN);
15509                                            }
15510                                    }
15511                            }
15512    
15513                            query.append(ORDER_BY_CLAUSE);
15514    
15515                            String[] orderByFields = orderByComparator.getOrderByFields();
15516    
15517                            for (int i = 0; i < orderByFields.length; i++) {
15518                                    if (getDB().isSupportsInlineDistinct()) {
15519                                            query.append(_ORDER_BY_ENTITY_ALIAS);
15520                                    }
15521                                    else {
15522                                            query.append(_ORDER_BY_ENTITY_TABLE);
15523                                    }
15524    
15525                                    query.append(orderByFields[i]);
15526    
15527                                    if ((i + 1) < orderByFields.length) {
15528                                            if (orderByComparator.isAscending() ^ previous) {
15529                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15530                                            }
15531                                            else {
15532                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15533                                            }
15534                                    }
15535                                    else {
15536                                            if (orderByComparator.isAscending() ^ previous) {
15537                                                    query.append(ORDER_BY_ASC);
15538                                            }
15539                                            else {
15540                                                    query.append(ORDER_BY_DESC);
15541                                            }
15542                                    }
15543                            }
15544                    }
15545    
15546                    else {
15547                            if (getDB().isSupportsInlineDistinct()) {
15548                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15549                            }
15550                            else {
15551                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
15552                            }
15553                    }
15554    
15555                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
15556                                    MBMessage.class.getName(),
15557                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
15558    
15559                    SQLQuery q = session.createSQLQuery(sql);
15560    
15561                    q.setFirstResult(0);
15562                    q.setMaxResults(2);
15563    
15564                    if (getDB().isSupportsInlineDistinct()) {
15565                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
15566                    }
15567                    else {
15568                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
15569                    }
15570    
15571                    QueryPos qPos = QueryPos.getInstance(q);
15572    
15573                    qPos.add(groupId);
15574    
15575                    qPos.add(categoryId);
15576    
15577                    qPos.add(threadId);
15578    
15579                    qPos.add(status);
15580    
15581                    if (orderByComparator != null) {
15582                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15583    
15584                            for (Object value : values) {
15585                                    qPos.add(value);
15586                            }
15587                    }
15588    
15589                    List<MBMessage> list = q.list();
15590    
15591                    if (list.size() == 2) {
15592                            return list.get(1);
15593                    }
15594                    else {
15595                            return null;
15596                    }
15597            }
15598    
15599            /**
15600             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15601             *
15602             * @param userId the user ID
15603             * @param classNameId the class name ID
15604             * @param classPK the class p k
15605             * @param status the status
15606             * @return the matching message-boards messages
15607             * @throws SystemException if a system exception occurred
15608             */
15609            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
15610                    long classPK, int status) throws SystemException {
15611                    return findByU_C_C_S(userId, classNameId, classPK, status,
15612                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15613            }
15614    
15615            /**
15616             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15617             *
15618             * <p>
15619             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
15620             * </p>
15621             *
15622             * @param userId the user ID
15623             * @param classNameId the class name ID
15624             * @param classPK the class p k
15625             * @param status the status
15626             * @param start the lower bound of the range of message-boards messages
15627             * @param end the upper bound of the range of message-boards messages (not inclusive)
15628             * @return the range of matching message-boards messages
15629             * @throws SystemException if a system exception occurred
15630             */
15631            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
15632                    long classPK, int status, int start, int end) throws SystemException {
15633                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
15634                            null);
15635            }
15636    
15637            /**
15638             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15639             *
15640             * <p>
15641             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
15642             * </p>
15643             *
15644             * @param userId the user ID
15645             * @param classNameId the class name ID
15646             * @param classPK the class p k
15647             * @param status the status
15648             * @param start the lower bound of the range of message-boards messages
15649             * @param end the upper bound of the range of message-boards messages (not inclusive)
15650             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15651             * @return the ordered range of matching message-boards messages
15652             * @throws SystemException if a system exception occurred
15653             */
15654            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
15655                    long classPK, int status, int start, int end,
15656                    OrderByComparator orderByComparator) throws SystemException {
15657                    FinderPath finderPath = null;
15658                    Object[] finderArgs = null;
15659    
15660                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15661                                    (orderByComparator == null)) {
15662                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
15663                            finderArgs = new Object[] { userId, classNameId, classPK, status };
15664                    }
15665                    else {
15666                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
15667                            finderArgs = new Object[] {
15668                                            userId, classNameId, classPK, status,
15669                                            
15670                                            start, end, orderByComparator
15671                                    };
15672                    }
15673    
15674                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15675                                    finderArgs, this);
15676    
15677                    if ((list != null) && !list.isEmpty()) {
15678                            for (MBMessage mbMessage : list) {
15679                                    if ((userId != mbMessage.getUserId()) ||
15680                                                    (classNameId != mbMessage.getClassNameId()) ||
15681                                                    (classPK != mbMessage.getClassPK()) ||
15682                                                    (status != mbMessage.getStatus())) {
15683                                            list = null;
15684    
15685                                            break;
15686                                    }
15687                            }
15688                    }
15689    
15690                    if (list == null) {
15691                            StringBundler query = null;
15692    
15693                            if (orderByComparator != null) {
15694                                    query = new StringBundler(6 +
15695                                                    (orderByComparator.getOrderByFields().length * 3));
15696                            }
15697                            else {
15698                                    query = new StringBundler(6);
15699                            }
15700    
15701                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15702    
15703                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
15704    
15705                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
15706    
15707                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
15708    
15709                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
15710    
15711                            if (orderByComparator != null) {
15712                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15713                                            orderByComparator);
15714                            }
15715    
15716                            else {
15717                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15718                            }
15719    
15720                            String sql = query.toString();
15721    
15722                            Session session = null;
15723    
15724                            try {
15725                                    session = openSession();
15726    
15727                                    Query q = session.createQuery(sql);
15728    
15729                                    QueryPos qPos = QueryPos.getInstance(q);
15730    
15731                                    qPos.add(userId);
15732    
15733                                    qPos.add(classNameId);
15734    
15735                                    qPos.add(classPK);
15736    
15737                                    qPos.add(status);
15738    
15739                                    list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
15740                                                    end);
15741                            }
15742                            catch (Exception e) {
15743                                    throw processException(e);
15744                            }
15745                            finally {
15746                                    if (list == null) {
15747                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
15748                                    }
15749                                    else {
15750                                            cacheResult(list);
15751    
15752                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
15753                                    }
15754    
15755                                    closeSession(session);
15756                            }
15757                    }
15758    
15759                    return list;
15760            }
15761    
15762            /**
15763             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15764             *
15765             * @param userId the user ID
15766             * @param classNameId the class name ID
15767             * @param classPK the class p k
15768             * @param status the status
15769             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15770             * @return the first matching message-boards message
15771             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15772             * @throws SystemException if a system exception occurred
15773             */
15774            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
15775                    long classPK, int status, OrderByComparator orderByComparator)
15776                    throws NoSuchMessageException, SystemException {
15777                    MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
15778                                    classPK, status, orderByComparator);
15779    
15780                    if (mbMessage != null) {
15781                            return mbMessage;
15782                    }
15783    
15784                    StringBundler msg = new StringBundler(10);
15785    
15786                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15787    
15788                    msg.append("userId=");
15789                    msg.append(userId);
15790    
15791                    msg.append(", classNameId=");
15792                    msg.append(classNameId);
15793    
15794                    msg.append(", classPK=");
15795                    msg.append(classPK);
15796    
15797                    msg.append(", status=");
15798                    msg.append(status);
15799    
15800                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15801    
15802                    throw new NoSuchMessageException(msg.toString());
15803            }
15804    
15805            /**
15806             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15807             *
15808             * @param userId the user ID
15809             * @param classNameId the class name ID
15810             * @param classPK the class p k
15811             * @param status the status
15812             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15813             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15814             * @throws SystemException if a system exception occurred
15815             */
15816            public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
15817                    long classPK, int status, OrderByComparator orderByComparator)
15818                    throws SystemException {
15819                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
15820                                    status, 0, 1, orderByComparator);
15821    
15822                    if (!list.isEmpty()) {
15823                            return list.get(0);
15824                    }
15825    
15826                    return null;
15827            }
15828    
15829            /**
15830             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15831             *
15832             * @param userId the user ID
15833             * @param classNameId the class name ID
15834             * @param classPK the class p k
15835             * @param status the status
15836             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15837             * @return the last matching message-boards message
15838             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15839             * @throws SystemException if a system exception occurred
15840             */
15841            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
15842                    long classPK, int status, OrderByComparator orderByComparator)
15843                    throws NoSuchMessageException, SystemException {
15844                    MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
15845                                    status, orderByComparator);
15846    
15847                    if (mbMessage != null) {
15848                            return mbMessage;
15849                    }
15850    
15851                    StringBundler msg = new StringBundler(10);
15852    
15853                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15854    
15855                    msg.append("userId=");
15856                    msg.append(userId);
15857    
15858                    msg.append(", classNameId=");
15859                    msg.append(classNameId);
15860    
15861                    msg.append(", classPK=");
15862                    msg.append(classPK);
15863    
15864                    msg.append(", status=");
15865                    msg.append(status);
15866    
15867                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15868    
15869                    throw new NoSuchMessageException(msg.toString());
15870            }
15871    
15872            /**
15873             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
15874             *
15875             * @param userId the user ID
15876             * @param classNameId the class name ID
15877             * @param classPK the class p k
15878             * @param status the status
15879             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15880             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15881             * @throws SystemException if a system exception occurred
15882             */
15883            public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
15884                    long classPK, int status, OrderByComparator orderByComparator)
15885                    throws SystemException {
15886                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
15887    
15888                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
15889                                    status, count - 1, count, orderByComparator);
15890    
15891                    if (!list.isEmpty()) {
15892                            return list.get(0);
15893                    }
15894    
15895                    return null;
15896            }
15897    
15898            /**
15899             * 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;.
15900             *
15901             * @param messageId the primary key of the current message-boards message
15902             * @param userId the user ID
15903             * @param classNameId the class name ID
15904             * @param classPK the class p k
15905             * @param status the status
15906             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15907             * @return the previous, current, and next message-boards message
15908             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
15909             * @throws SystemException if a system exception occurred
15910             */
15911            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
15912                    long classNameId, long classPK, int status,
15913                    OrderByComparator orderByComparator)
15914                    throws NoSuchMessageException, SystemException {
15915                    MBMessage mbMessage = findByPrimaryKey(messageId);
15916    
15917                    Session session = null;
15918    
15919                    try {
15920                            session = openSession();
15921    
15922                            MBMessage[] array = new MBMessageImpl[3];
15923    
15924                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
15925                                            classNameId, classPK, status, orderByComparator, true);
15926    
15927                            array[1] = mbMessage;
15928    
15929                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
15930                                            classNameId, classPK, status, orderByComparator, false);
15931    
15932                            return array;
15933                    }
15934                    catch (Exception e) {
15935                            throw processException(e);
15936                    }
15937                    finally {
15938                            closeSession(session);
15939                    }
15940            }
15941    
15942            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
15943                    MBMessage mbMessage, long userId, long classNameId, long classPK,
15944                    int status, OrderByComparator orderByComparator, boolean previous) {
15945                    StringBundler query = null;
15946    
15947                    if (orderByComparator != null) {
15948                            query = new StringBundler(6 +
15949                                            (orderByComparator.getOrderByFields().length * 6));
15950                    }
15951                    else {
15952                            query = new StringBundler(3);
15953                    }
15954    
15955                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15956    
15957                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
15958    
15959                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
15960    
15961                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
15962    
15963                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
15964    
15965                    if (orderByComparator != null) {
15966                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15967    
15968                            if (orderByConditionFields.length > 0) {
15969                                    query.append(WHERE_AND);
15970                            }
15971    
15972                            for (int i = 0; i < orderByConditionFields.length; i++) {
15973                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15974                                    query.append(orderByConditionFields[i]);
15975    
15976                                    if ((i + 1) < orderByConditionFields.length) {
15977                                            if (orderByComparator.isAscending() ^ previous) {
15978                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15979                                            }
15980                                            else {
15981                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15982                                            }
15983                                    }
15984                                    else {
15985                                            if (orderByComparator.isAscending() ^ previous) {
15986                                                    query.append(WHERE_GREATER_THAN);
15987                                            }
15988                                            else {
15989                                                    query.append(WHERE_LESSER_THAN);
15990                                            }
15991                                    }
15992                            }
15993    
15994                            query.append(ORDER_BY_CLAUSE);
15995    
15996                            String[] orderByFields = orderByComparator.getOrderByFields();
15997    
15998                            for (int i = 0; i < orderByFields.length; i++) {
15999                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16000                                    query.append(orderByFields[i]);
16001    
16002                                    if ((i + 1) < orderByFields.length) {
16003                                            if (orderByComparator.isAscending() ^ previous) {
16004                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16005                                            }
16006                                            else {
16007                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16008                                            }
16009                                    }
16010                                    else {
16011                                            if (orderByComparator.isAscending() ^ previous) {
16012                                                    query.append(ORDER_BY_ASC);
16013                                            }
16014                                            else {
16015                                                    query.append(ORDER_BY_DESC);
16016                                            }
16017                                    }
16018                            }
16019                    }
16020    
16021                    else {
16022                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16023                    }
16024    
16025                    String sql = query.toString();
16026    
16027                    Query q = session.createQuery(sql);
16028    
16029                    q.setFirstResult(0);
16030                    q.setMaxResults(2);
16031    
16032                    QueryPos qPos = QueryPos.getInstance(q);
16033    
16034                    qPos.add(userId);
16035    
16036                    qPos.add(classNameId);
16037    
16038                    qPos.add(classPK);
16039    
16040                    qPos.add(status);
16041    
16042                    if (orderByComparator != null) {
16043                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16044    
16045                            for (Object value : values) {
16046                                    qPos.add(value);
16047                            }
16048                    }
16049    
16050                    List<MBMessage> list = q.list();
16051    
16052                    if (list.size() == 2) {
16053                            return list.get(1);
16054                    }
16055                    else {
16056                            return null;
16057                    }
16058            }
16059    
16060            /**
16061             * Returns all the message-boards messages.
16062             *
16063             * @return the message-boards messages
16064             * @throws SystemException if a system exception occurred
16065             */
16066            public List<MBMessage> findAll() throws SystemException {
16067                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16068            }
16069    
16070            /**
16071             * Returns a range of all the message-boards messages.
16072             *
16073             * <p>
16074             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
16075             * </p>
16076             *
16077             * @param start the lower bound of the range of message-boards messages
16078             * @param end the upper bound of the range of message-boards messages (not inclusive)
16079             * @return the range of message-boards messages
16080             * @throws SystemException if a system exception occurred
16081             */
16082            public List<MBMessage> findAll(int start, int end)
16083                    throws SystemException {
16084                    return findAll(start, end, null);
16085            }
16086    
16087            /**
16088             * Returns an ordered range of all the message-boards messages.
16089             *
16090             * <p>
16091             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
16092             * </p>
16093             *
16094             * @param start the lower bound of the range of message-boards messages
16095             * @param end the upper bound of the range of message-boards messages (not inclusive)
16096             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16097             * @return the ordered range of message-boards messages
16098             * @throws SystemException if a system exception occurred
16099             */
16100            public List<MBMessage> findAll(int start, int end,
16101                    OrderByComparator orderByComparator) throws SystemException {
16102                    FinderPath finderPath = null;
16103                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
16104    
16105                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16106                                    (orderByComparator == null)) {
16107                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
16108                            finderArgs = FINDER_ARGS_EMPTY;
16109                    }
16110                    else {
16111                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
16112                            finderArgs = new Object[] { start, end, orderByComparator };
16113                    }
16114    
16115                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
16116                                    finderArgs, this);
16117    
16118                    if (list == null) {
16119                            StringBundler query = null;
16120                            String sql = null;
16121    
16122                            if (orderByComparator != null) {
16123                                    query = new StringBundler(2 +
16124                                                    (orderByComparator.getOrderByFields().length * 3));
16125    
16126                                    query.append(_SQL_SELECT_MBMESSAGE);
16127    
16128                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16129                                            orderByComparator);
16130    
16131                                    sql = query.toString();
16132                            }
16133                            else {
16134                                    sql = _SQL_SELECT_MBMESSAGE.concat(MBMessageModelImpl.ORDER_BY_JPQL);
16135                            }
16136    
16137                            Session session = null;
16138    
16139                            try {
16140                                    session = openSession();
16141    
16142                                    Query q = session.createQuery(sql);
16143    
16144                                    if (orderByComparator == null) {
16145                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16146                                                            start, end, false);
16147    
16148                                            Collections.sort(list);
16149                                    }
16150                                    else {
16151                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16152                                                            start, end);
16153                                    }
16154                            }
16155                            catch (Exception e) {
16156                                    throw processException(e);
16157                            }
16158                            finally {
16159                                    if (list == null) {
16160                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
16161                                    }
16162                                    else {
16163                                            cacheResult(list);
16164    
16165                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
16166                                    }
16167    
16168                                    closeSession(session);
16169                            }
16170                    }
16171    
16172                    return list;
16173            }
16174    
16175            /**
16176             * Removes all the message-boards messages where uuid = &#63; from the database.
16177             *
16178             * @param uuid the uuid
16179             * @throws SystemException if a system exception occurred
16180             */
16181            public void removeByUuid(String uuid) throws SystemException {
16182                    for (MBMessage mbMessage : findByUuid(uuid)) {
16183                            remove(mbMessage);
16184                    }
16185            }
16186    
16187            /**
16188             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
16189             *
16190             * @param uuid the uuid
16191             * @param groupId the group ID
16192             * @return the message-boards message that was removed
16193             * @throws SystemException if a system exception occurred
16194             */
16195            public MBMessage removeByUUID_G(String uuid, long groupId)
16196                    throws NoSuchMessageException, SystemException {
16197                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
16198    
16199                    return remove(mbMessage);
16200            }
16201    
16202            /**
16203             * Removes all the message-boards messages where uuid = &#63; and companyId = &#63; from the database.
16204             *
16205             * @param uuid the uuid
16206             * @param companyId the company ID
16207             * @throws SystemException if a system exception occurred
16208             */
16209            public void removeByUuid_C(String uuid, long companyId)
16210                    throws SystemException {
16211                    for (MBMessage mbMessage : findByUuid_C(uuid, companyId)) {
16212                            remove(mbMessage);
16213                    }
16214            }
16215    
16216            /**
16217             * Removes all the message-boards messages where groupId = &#63; from the database.
16218             *
16219             * @param groupId the group ID
16220             * @throws SystemException if a system exception occurred
16221             */
16222            public void removeByGroupId(long groupId) throws SystemException {
16223                    for (MBMessage mbMessage : findByGroupId(groupId)) {
16224                            remove(mbMessage);
16225                    }
16226            }
16227    
16228            /**
16229             * Removes all the message-boards messages where companyId = &#63; from the database.
16230             *
16231             * @param companyId the company ID
16232             * @throws SystemException if a system exception occurred
16233             */
16234            public void removeByCompanyId(long companyId) throws SystemException {
16235                    for (MBMessage mbMessage : findByCompanyId(companyId)) {
16236                            remove(mbMessage);
16237                    }
16238            }
16239    
16240            /**
16241             * Removes all the message-boards messages where threadId = &#63; from the database.
16242             *
16243             * @param threadId the thread ID
16244             * @throws SystemException if a system exception occurred
16245             */
16246            public void removeByThreadId(long threadId) throws SystemException {
16247                    for (MBMessage mbMessage : findByThreadId(threadId)) {
16248                            remove(mbMessage);
16249                    }
16250            }
16251    
16252            /**
16253             * Removes all the message-boards messages where threadId = &#63; from the database.
16254             *
16255             * @param threadId the thread ID
16256             * @throws SystemException if a system exception occurred
16257             */
16258            public void removeByThreadReplies(long threadId) throws SystemException {
16259                    for (MBMessage mbMessage : findByThreadReplies(threadId)) {
16260                            remove(mbMessage);
16261                    }
16262            }
16263    
16264            /**
16265             * Removes all the message-boards messages where userId = &#63; from the database.
16266             *
16267             * @param userId the user ID
16268             * @throws SystemException if a system exception occurred
16269             */
16270            public void removeByUserId(long userId) throws SystemException {
16271                    for (MBMessage mbMessage : findByUserId(userId)) {
16272                            remove(mbMessage);
16273                    }
16274            }
16275    
16276            /**
16277             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
16278             *
16279             * @param groupId the group ID
16280             * @param userId the user ID
16281             * @throws SystemException if a system exception occurred
16282             */
16283            public void removeByG_U(long groupId, long userId)
16284                    throws SystemException {
16285                    for (MBMessage mbMessage : findByG_U(groupId, userId)) {
16286                            remove(mbMessage);
16287                    }
16288            }
16289    
16290            /**
16291             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
16292             *
16293             * @param groupId the group ID
16294             * @param categoryId the category ID
16295             * @throws SystemException if a system exception occurred
16296             */
16297            public void removeByG_C(long groupId, long categoryId)
16298                    throws SystemException {
16299                    for (MBMessage mbMessage : findByG_C(groupId, categoryId)) {
16300                            remove(mbMessage);
16301                    }
16302            }
16303    
16304            /**
16305             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
16306             *
16307             * @param groupId the group ID
16308             * @param status the status
16309             * @throws SystemException if a system exception occurred
16310             */
16311            public void removeByG_S(long groupId, int status) throws SystemException {
16312                    for (MBMessage mbMessage : findByG_S(groupId, status)) {
16313                            remove(mbMessage);
16314                    }
16315            }
16316    
16317            /**
16318             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
16319             *
16320             * @param companyId the company ID
16321             * @param status the status
16322             * @throws SystemException if a system exception occurred
16323             */
16324            public void removeByC_S(long companyId, int status)
16325                    throws SystemException {
16326                    for (MBMessage mbMessage : findByC_S(companyId, status)) {
16327                            remove(mbMessage);
16328                    }
16329            }
16330    
16331            /**
16332             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
16333             *
16334             * @param userId the user ID
16335             * @param classNameId the class name ID
16336             * @throws SystemException if a system exception occurred
16337             */
16338            public void removeByU_C(long userId, long classNameId)
16339                    throws SystemException {
16340                    for (MBMessage mbMessage : findByU_C(userId, classNameId)) {
16341                            remove(mbMessage);
16342                    }
16343            }
16344    
16345            /**
16346             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
16347             *
16348             * @param classNameId the class name ID
16349             * @param classPK the class p k
16350             * @throws SystemException if a system exception occurred
16351             */
16352            public void removeByC_C(long classNameId, long classPK)
16353                    throws SystemException {
16354                    for (MBMessage mbMessage : findByC_C(classNameId, classPK)) {
16355                            remove(mbMessage);
16356                    }
16357            }
16358    
16359            /**
16360             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
16361             *
16362             * @param threadId the thread ID
16363             * @param parentMessageId the parent message ID
16364             * @throws SystemException if a system exception occurred
16365             */
16366            public void removeByT_P(long threadId, long parentMessageId)
16367                    throws SystemException {
16368                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId)) {
16369                            remove(mbMessage);
16370                    }
16371            }
16372    
16373            /**
16374             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
16375             *
16376             * @param threadId the thread ID
16377             * @param answer the answer
16378             * @throws SystemException if a system exception occurred
16379             */
16380            public void removeByT_A(long threadId, boolean answer)
16381                    throws SystemException {
16382                    for (MBMessage mbMessage : findByT_A(threadId, answer)) {
16383                            remove(mbMessage);
16384                    }
16385            }
16386    
16387            /**
16388             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
16389             *
16390             * @param threadId the thread ID
16391             * @param status the status
16392             * @throws SystemException if a system exception occurred
16393             */
16394            public void removeByT_S(long threadId, int status)
16395                    throws SystemException {
16396                    for (MBMessage mbMessage : findByT_S(threadId, status)) {
16397                            remove(mbMessage);
16398                    }
16399            }
16400    
16401            /**
16402             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
16403             *
16404             * @param threadId the thread ID
16405             * @param status the status
16406             * @throws SystemException if a system exception occurred
16407             */
16408            public void removeByTR_S(long threadId, int status)
16409                    throws SystemException {
16410                    for (MBMessage mbMessage : findByTR_S(threadId, status)) {
16411                            remove(mbMessage);
16412                    }
16413            }
16414    
16415            /**
16416             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
16417             *
16418             * @param groupId the group ID
16419             * @param userId the user ID
16420             * @param status the status
16421             * @throws SystemException if a system exception occurred
16422             */
16423            public void removeByG_U_S(long groupId, long userId, int status)
16424                    throws SystemException {
16425                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status)) {
16426                            remove(mbMessage);
16427                    }
16428            }
16429    
16430            /**
16431             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
16432             *
16433             * @param groupId the group ID
16434             * @param categoryId the category ID
16435             * @param threadId the thread ID
16436             * @throws SystemException if a system exception occurred
16437             */
16438            public void removeByG_C_T(long groupId, long categoryId, long threadId)
16439                    throws SystemException {
16440                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId)) {
16441                            remove(mbMessage);
16442                    }
16443            }
16444    
16445            /**
16446             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
16447             *
16448             * @param groupId the group ID
16449             * @param categoryId the category ID
16450             * @param status the status
16451             * @throws SystemException if a system exception occurred
16452             */
16453            public void removeByG_C_S(long groupId, long categoryId, int status)
16454                    throws SystemException {
16455                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status)) {
16456                            remove(mbMessage);
16457                    }
16458            }
16459    
16460            /**
16461             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
16462             *
16463             * @param userId the user ID
16464             * @param classNameId the class name ID
16465             * @param classPK the class p k
16466             * @throws SystemException if a system exception occurred
16467             */
16468            public void removeByU_C_C(long userId, long classNameId, long classPK)
16469                    throws SystemException {
16470                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK)) {
16471                            remove(mbMessage);
16472                    }
16473            }
16474    
16475            /**
16476             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
16477             *
16478             * @param userId the user ID
16479             * @param classNameId the class name ID
16480             * @param status the status
16481             * @throws SystemException if a system exception occurred
16482             */
16483            public void removeByU_C_S(long userId, long classNameId, int status)
16484                    throws SystemException {
16485                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status)) {
16486                            remove(mbMessage);
16487                    }
16488            }
16489    
16490            /**
16491             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
16492             *
16493             * @param classNameId the class name ID
16494             * @param classPK the class p k
16495             * @param status the status
16496             * @throws SystemException if a system exception occurred
16497             */
16498            public void removeByC_C_S(long classNameId, long classPK, int status)
16499                    throws SystemException {
16500                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status)) {
16501                            remove(mbMessage);
16502                    }
16503            }
16504    
16505            /**
16506             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
16507             *
16508             * @param groupId the group ID
16509             * @param categoryId the category ID
16510             * @param threadId the thread ID
16511             * @param answer the answer
16512             * @throws SystemException if a system exception occurred
16513             */
16514            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
16515                    boolean answer) throws SystemException {
16516                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
16517                                    answer)) {
16518                            remove(mbMessage);
16519                    }
16520            }
16521    
16522            /**
16523             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
16524             *
16525             * @param groupId the group ID
16526             * @param categoryId the category ID
16527             * @param threadId the thread ID
16528             * @param status the status
16529             * @throws SystemException if a system exception occurred
16530             */
16531            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
16532                    int status) throws SystemException {
16533                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
16534                                    status)) {
16535                            remove(mbMessage);
16536                    }
16537            }
16538    
16539            /**
16540             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
16541             *
16542             * @param userId the user ID
16543             * @param classNameId the class name ID
16544             * @param classPK the class p k
16545             * @param status the status
16546             * @throws SystemException if a system exception occurred
16547             */
16548            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
16549                    int status) throws SystemException {
16550                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
16551                                    status)) {
16552                            remove(mbMessage);
16553                    }
16554            }
16555    
16556            /**
16557             * Removes all the message-boards messages from the database.
16558             *
16559             * @throws SystemException if a system exception occurred
16560             */
16561            public void removeAll() throws SystemException {
16562                    for (MBMessage mbMessage : findAll()) {
16563                            remove(mbMessage);
16564                    }
16565            }
16566    
16567            /**
16568             * Returns the number of message-boards messages where uuid = &#63;.
16569             *
16570             * @param uuid the uuid
16571             * @return the number of matching message-boards messages
16572             * @throws SystemException if a system exception occurred
16573             */
16574            public int countByUuid(String uuid) throws SystemException {
16575                    Object[] finderArgs = new Object[] { uuid };
16576    
16577                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
16578                                    finderArgs, this);
16579    
16580                    if (count == null) {
16581                            StringBundler query = new StringBundler(2);
16582    
16583                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16584    
16585                            if (uuid == null) {
16586                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
16587                            }
16588                            else {
16589                                    if (uuid.equals(StringPool.BLANK)) {
16590                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
16591                                    }
16592                                    else {
16593                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
16594                                    }
16595                            }
16596    
16597                            String sql = query.toString();
16598    
16599                            Session session = null;
16600    
16601                            try {
16602                                    session = openSession();
16603    
16604                                    Query q = session.createQuery(sql);
16605    
16606                                    QueryPos qPos = QueryPos.getInstance(q);
16607    
16608                                    if (uuid != null) {
16609                                            qPos.add(uuid);
16610                                    }
16611    
16612                                    count = (Long)q.uniqueResult();
16613                            }
16614                            catch (Exception e) {
16615                                    throw processException(e);
16616                            }
16617                            finally {
16618                                    if (count == null) {
16619                                            count = Long.valueOf(0);
16620                                    }
16621    
16622                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
16623                                            finderArgs, count);
16624    
16625                                    closeSession(session);
16626                            }
16627                    }
16628    
16629                    return count.intValue();
16630            }
16631    
16632            /**
16633             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
16634             *
16635             * @param uuid the uuid
16636             * @param groupId the group ID
16637             * @return the number of matching message-boards messages
16638             * @throws SystemException if a system exception occurred
16639             */
16640            public int countByUUID_G(String uuid, long groupId)
16641                    throws SystemException {
16642                    Object[] finderArgs = new Object[] { uuid, groupId };
16643    
16644                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
16645                                    finderArgs, this);
16646    
16647                    if (count == null) {
16648                            StringBundler query = new StringBundler(3);
16649    
16650                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16651    
16652                            if (uuid == null) {
16653                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
16654                            }
16655                            else {
16656                                    if (uuid.equals(StringPool.BLANK)) {
16657                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
16658                                    }
16659                                    else {
16660                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
16661                                    }
16662                            }
16663    
16664                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
16665    
16666                            String sql = query.toString();
16667    
16668                            Session session = null;
16669    
16670                            try {
16671                                    session = openSession();
16672    
16673                                    Query q = session.createQuery(sql);
16674    
16675                                    QueryPos qPos = QueryPos.getInstance(q);
16676    
16677                                    if (uuid != null) {
16678                                            qPos.add(uuid);
16679                                    }
16680    
16681                                    qPos.add(groupId);
16682    
16683                                    count = (Long)q.uniqueResult();
16684                            }
16685                            catch (Exception e) {
16686                                    throw processException(e);
16687                            }
16688                            finally {
16689                                    if (count == null) {
16690                                            count = Long.valueOf(0);
16691                                    }
16692    
16693                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
16694                                            finderArgs, count);
16695    
16696                                    closeSession(session);
16697                            }
16698                    }
16699    
16700                    return count.intValue();
16701            }
16702    
16703            /**
16704             * Returns the number of message-boards messages where uuid = &#63; and companyId = &#63;.
16705             *
16706             * @param uuid the uuid
16707             * @param companyId the company ID
16708             * @return the number of matching message-boards messages
16709             * @throws SystemException if a system exception occurred
16710             */
16711            public int countByUuid_C(String uuid, long companyId)
16712                    throws SystemException {
16713                    Object[] finderArgs = new Object[] { uuid, companyId };
16714    
16715                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_C,
16716                                    finderArgs, this);
16717    
16718                    if (count == null) {
16719                            StringBundler query = new StringBundler(3);
16720    
16721                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16722    
16723                            if (uuid == null) {
16724                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
16725                            }
16726                            else {
16727                                    if (uuid.equals(StringPool.BLANK)) {
16728                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
16729                                    }
16730                                    else {
16731                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
16732                                    }
16733                            }
16734    
16735                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
16736    
16737                            String sql = query.toString();
16738    
16739                            Session session = null;
16740    
16741                            try {
16742                                    session = openSession();
16743    
16744                                    Query q = session.createQuery(sql);
16745    
16746                                    QueryPos qPos = QueryPos.getInstance(q);
16747    
16748                                    if (uuid != null) {
16749                                            qPos.add(uuid);
16750                                    }
16751    
16752                                    qPos.add(companyId);
16753    
16754                                    count = (Long)q.uniqueResult();
16755                            }
16756                            catch (Exception e) {
16757                                    throw processException(e);
16758                            }
16759                            finally {
16760                                    if (count == null) {
16761                                            count = Long.valueOf(0);
16762                                    }
16763    
16764                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_C,
16765                                            finderArgs, count);
16766    
16767                                    closeSession(session);
16768                            }
16769                    }
16770    
16771                    return count.intValue();
16772            }
16773    
16774            /**
16775             * Returns the number of message-boards messages where groupId = &#63;.
16776             *
16777             * @param groupId the group ID
16778             * @return the number of matching message-boards messages
16779             * @throws SystemException if a system exception occurred
16780             */
16781            public int countByGroupId(long groupId) throws SystemException {
16782                    Object[] finderArgs = new Object[] { groupId };
16783    
16784                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
16785                                    finderArgs, this);
16786    
16787                    if (count == null) {
16788                            StringBundler query = new StringBundler(2);
16789    
16790                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16791    
16792                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
16793    
16794                            String sql = query.toString();
16795    
16796                            Session session = null;
16797    
16798                            try {
16799                                    session = openSession();
16800    
16801                                    Query q = session.createQuery(sql);
16802    
16803                                    QueryPos qPos = QueryPos.getInstance(q);
16804    
16805                                    qPos.add(groupId);
16806    
16807                                    count = (Long)q.uniqueResult();
16808                            }
16809                            catch (Exception e) {
16810                                    throw processException(e);
16811                            }
16812                            finally {
16813                                    if (count == null) {
16814                                            count = Long.valueOf(0);
16815                                    }
16816    
16817                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
16818                                            finderArgs, count);
16819    
16820                                    closeSession(session);
16821                            }
16822                    }
16823    
16824                    return count.intValue();
16825            }
16826    
16827            /**
16828             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
16829             *
16830             * @param groupId the group ID
16831             * @return the number of matching message-boards messages that the user has permission to view
16832             * @throws SystemException if a system exception occurred
16833             */
16834            public int filterCountByGroupId(long groupId) throws SystemException {
16835                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16836                            return countByGroupId(groupId);
16837                    }
16838    
16839                    StringBundler query = new StringBundler(2);
16840    
16841                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16842    
16843                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
16844    
16845                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16846                                    MBMessage.class.getName(),
16847                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16848    
16849                    Session session = null;
16850    
16851                    try {
16852                            session = openSession();
16853    
16854                            SQLQuery q = session.createSQLQuery(sql);
16855    
16856                            q.addScalar(COUNT_COLUMN_NAME,
16857                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16858    
16859                            QueryPos qPos = QueryPos.getInstance(q);
16860    
16861                            qPos.add(groupId);
16862    
16863                            Long count = (Long)q.uniqueResult();
16864    
16865                            return count.intValue();
16866                    }
16867                    catch (Exception e) {
16868                            throw processException(e);
16869                    }
16870                    finally {
16871                            closeSession(session);
16872                    }
16873            }
16874    
16875            /**
16876             * Returns the number of message-boards messages where companyId = &#63;.
16877             *
16878             * @param companyId the company ID
16879             * @return the number of matching message-boards messages
16880             * @throws SystemException if a system exception occurred
16881             */
16882            public int countByCompanyId(long companyId) throws SystemException {
16883                    Object[] finderArgs = new Object[] { companyId };
16884    
16885                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
16886                                    finderArgs, this);
16887    
16888                    if (count == null) {
16889                            StringBundler query = new StringBundler(2);
16890    
16891                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16892    
16893                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
16894    
16895                            String sql = query.toString();
16896    
16897                            Session session = null;
16898    
16899                            try {
16900                                    session = openSession();
16901    
16902                                    Query q = session.createQuery(sql);
16903    
16904                                    QueryPos qPos = QueryPos.getInstance(q);
16905    
16906                                    qPos.add(companyId);
16907    
16908                                    count = (Long)q.uniqueResult();
16909                            }
16910                            catch (Exception e) {
16911                                    throw processException(e);
16912                            }
16913                            finally {
16914                                    if (count == null) {
16915                                            count = Long.valueOf(0);
16916                                    }
16917    
16918                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
16919                                            finderArgs, count);
16920    
16921                                    closeSession(session);
16922                            }
16923                    }
16924    
16925                    return count.intValue();
16926            }
16927    
16928            /**
16929             * Returns the number of message-boards messages where threadId = &#63;.
16930             *
16931             * @param threadId the thread ID
16932             * @return the number of matching message-boards messages
16933             * @throws SystemException if a system exception occurred
16934             */
16935            public int countByThreadId(long threadId) throws SystemException {
16936                    Object[] finderArgs = new Object[] { threadId };
16937    
16938                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
16939                                    finderArgs, this);
16940    
16941                    if (count == null) {
16942                            StringBundler query = new StringBundler(2);
16943    
16944                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16945    
16946                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
16947    
16948                            String sql = query.toString();
16949    
16950                            Session session = null;
16951    
16952                            try {
16953                                    session = openSession();
16954    
16955                                    Query q = session.createQuery(sql);
16956    
16957                                    QueryPos qPos = QueryPos.getInstance(q);
16958    
16959                                    qPos.add(threadId);
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_THREADID,
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 threadId = &#63;.
16983             *
16984             * @param threadId the thread ID
16985             * @return the number of matching message-boards messages
16986             * @throws SystemException if a system exception occurred
16987             */
16988            public int countByThreadReplies(long threadId) throws SystemException {
16989                    Object[] finderArgs = new Object[] { threadId };
16990    
16991                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
16992                                    finderArgs, this);
16993    
16994                    if (count == null) {
16995                            StringBundler query = new StringBundler(2);
16996    
16997                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16998    
16999                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
17000    
17001                            String sql = query.toString();
17002    
17003                            Session session = null;
17004    
17005                            try {
17006                                    session = openSession();
17007    
17008                                    Query q = session.createQuery(sql);
17009    
17010                                    QueryPos qPos = QueryPos.getInstance(q);
17011    
17012                                    qPos.add(threadId);
17013    
17014                                    count = (Long)q.uniqueResult();
17015                            }
17016                            catch (Exception e) {
17017                                    throw processException(e);
17018                            }
17019                            finally {
17020                                    if (count == null) {
17021                                            count = Long.valueOf(0);
17022                                    }
17023    
17024                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
17025                                            finderArgs, count);
17026    
17027                                    closeSession(session);
17028                            }
17029                    }
17030    
17031                    return count.intValue();
17032            }
17033    
17034            /**
17035             * Returns the number of message-boards messages where userId = &#63;.
17036             *
17037             * @param userId the user ID
17038             * @return the number of matching message-boards messages
17039             * @throws SystemException if a system exception occurred
17040             */
17041            public int countByUserId(long userId) throws SystemException {
17042                    Object[] finderArgs = new Object[] { userId };
17043    
17044                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
17045                                    finderArgs, this);
17046    
17047                    if (count == null) {
17048                            StringBundler query = new StringBundler(2);
17049    
17050                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17051    
17052                            query.append(_FINDER_COLUMN_USERID_USERID_2);
17053    
17054                            String sql = query.toString();
17055    
17056                            Session session = null;
17057    
17058                            try {
17059                                    session = openSession();
17060    
17061                                    Query q = session.createQuery(sql);
17062    
17063                                    QueryPos qPos = QueryPos.getInstance(q);
17064    
17065                                    qPos.add(userId);
17066    
17067                                    count = (Long)q.uniqueResult();
17068                            }
17069                            catch (Exception e) {
17070                                    throw processException(e);
17071                            }
17072                            finally {
17073                                    if (count == null) {
17074                                            count = Long.valueOf(0);
17075                                    }
17076    
17077                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
17078                                            finderArgs, count);
17079    
17080                                    closeSession(session);
17081                            }
17082                    }
17083    
17084                    return count.intValue();
17085            }
17086    
17087            /**
17088             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
17089             *
17090             * @param groupId the group ID
17091             * @param userId the user ID
17092             * @return the number of matching message-boards messages
17093             * @throws SystemException if a system exception occurred
17094             */
17095            public int countByG_U(long groupId, long userId) throws SystemException {
17096                    Object[] finderArgs = new Object[] { groupId, userId };
17097    
17098                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
17099                                    finderArgs, this);
17100    
17101                    if (count == null) {
17102                            StringBundler query = new StringBundler(3);
17103    
17104                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17105    
17106                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
17107    
17108                            query.append(_FINDER_COLUMN_G_U_USERID_2);
17109    
17110                            String sql = query.toString();
17111    
17112                            Session session = null;
17113    
17114                            try {
17115                                    session = openSession();
17116    
17117                                    Query q = session.createQuery(sql);
17118    
17119                                    QueryPos qPos = QueryPos.getInstance(q);
17120    
17121                                    qPos.add(groupId);
17122    
17123                                    qPos.add(userId);
17124    
17125                                    count = (Long)q.uniqueResult();
17126                            }
17127                            catch (Exception e) {
17128                                    throw processException(e);
17129                            }
17130                            finally {
17131                                    if (count == null) {
17132                                            count = Long.valueOf(0);
17133                                    }
17134    
17135                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
17136                                            count);
17137    
17138                                    closeSession(session);
17139                            }
17140                    }
17141    
17142                    return count.intValue();
17143            }
17144    
17145            /**
17146             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
17147             *
17148             * @param groupId the group ID
17149             * @param userId the user ID
17150             * @return the number of matching message-boards messages that the user has permission to view
17151             * @throws SystemException if a system exception occurred
17152             */
17153            public int filterCountByG_U(long groupId, long userId)
17154                    throws SystemException {
17155                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17156                            return countByG_U(groupId, userId);
17157                    }
17158    
17159                    StringBundler query = new StringBundler(3);
17160    
17161                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17162    
17163                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
17164    
17165                    query.append(_FINDER_COLUMN_G_U_USERID_2);
17166    
17167                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17168                                    MBMessage.class.getName(),
17169                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17170    
17171                    Session session = null;
17172    
17173                    try {
17174                            session = openSession();
17175    
17176                            SQLQuery q = session.createSQLQuery(sql);
17177    
17178                            q.addScalar(COUNT_COLUMN_NAME,
17179                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17180    
17181                            QueryPos qPos = QueryPos.getInstance(q);
17182    
17183                            qPos.add(groupId);
17184    
17185                            qPos.add(userId);
17186    
17187                            Long count = (Long)q.uniqueResult();
17188    
17189                            return count.intValue();
17190                    }
17191                    catch (Exception e) {
17192                            throw processException(e);
17193                    }
17194                    finally {
17195                            closeSession(session);
17196                    }
17197            }
17198    
17199            /**
17200             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
17201             *
17202             * @param groupId the group ID
17203             * @param categoryId the category ID
17204             * @return the number of matching message-boards messages
17205             * @throws SystemException if a system exception occurred
17206             */
17207            public int countByG_C(long groupId, long categoryId)
17208                    throws SystemException {
17209                    Object[] finderArgs = new Object[] { groupId, categoryId };
17210    
17211                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
17212                                    finderArgs, this);
17213    
17214                    if (count == null) {
17215                            StringBundler query = new StringBundler(3);
17216    
17217                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17218    
17219                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
17220    
17221                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
17222    
17223                            String sql = query.toString();
17224    
17225                            Session session = null;
17226    
17227                            try {
17228                                    session = openSession();
17229    
17230                                    Query q = session.createQuery(sql);
17231    
17232                                    QueryPos qPos = QueryPos.getInstance(q);
17233    
17234                                    qPos.add(groupId);
17235    
17236                                    qPos.add(categoryId);
17237    
17238                                    count = (Long)q.uniqueResult();
17239                            }
17240                            catch (Exception e) {
17241                                    throw processException(e);
17242                            }
17243                            finally {
17244                                    if (count == null) {
17245                                            count = Long.valueOf(0);
17246                                    }
17247    
17248                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
17249                                            count);
17250    
17251                                    closeSession(session);
17252                            }
17253                    }
17254    
17255                    return count.intValue();
17256            }
17257    
17258            /**
17259             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
17260             *
17261             * @param groupId the group ID
17262             * @param categoryId the category ID
17263             * @return the number of matching message-boards messages that the user has permission to view
17264             * @throws SystemException if a system exception occurred
17265             */
17266            public int filterCountByG_C(long groupId, long categoryId)
17267                    throws SystemException {
17268                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17269                            return countByG_C(groupId, categoryId);
17270                    }
17271    
17272                    StringBundler query = new StringBundler(3);
17273    
17274                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17275    
17276                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
17277    
17278                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
17279    
17280                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17281                                    MBMessage.class.getName(),
17282                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17283    
17284                    Session session = null;
17285    
17286                    try {
17287                            session = openSession();
17288    
17289                            SQLQuery q = session.createSQLQuery(sql);
17290    
17291                            q.addScalar(COUNT_COLUMN_NAME,
17292                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17293    
17294                            QueryPos qPos = QueryPos.getInstance(q);
17295    
17296                            qPos.add(groupId);
17297    
17298                            qPos.add(categoryId);
17299    
17300                            Long count = (Long)q.uniqueResult();
17301    
17302                            return count.intValue();
17303                    }
17304                    catch (Exception e) {
17305                            throw processException(e);
17306                    }
17307                    finally {
17308                            closeSession(session);
17309                    }
17310            }
17311    
17312            /**
17313             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
17314             *
17315             * @param groupId the group ID
17316             * @param status the status
17317             * @return the number of matching message-boards messages
17318             * @throws SystemException if a system exception occurred
17319             */
17320            public int countByG_S(long groupId, int status) throws SystemException {
17321                    Object[] finderArgs = new Object[] { groupId, status };
17322    
17323                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
17324                                    finderArgs, this);
17325    
17326                    if (count == null) {
17327                            StringBundler query = new StringBundler(3);
17328    
17329                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17330    
17331                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
17332    
17333                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
17334    
17335                            String sql = query.toString();
17336    
17337                            Session session = null;
17338    
17339                            try {
17340                                    session = openSession();
17341    
17342                                    Query q = session.createQuery(sql);
17343    
17344                                    QueryPos qPos = QueryPos.getInstance(q);
17345    
17346                                    qPos.add(groupId);
17347    
17348                                    qPos.add(status);
17349    
17350                                    count = (Long)q.uniqueResult();
17351                            }
17352                            catch (Exception e) {
17353                                    throw processException(e);
17354                            }
17355                            finally {
17356                                    if (count == null) {
17357                                            count = Long.valueOf(0);
17358                                    }
17359    
17360                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
17361                                            count);
17362    
17363                                    closeSession(session);
17364                            }
17365                    }
17366    
17367                    return count.intValue();
17368            }
17369    
17370            /**
17371             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
17372             *
17373             * @param groupId the group ID
17374             * @param status the status
17375             * @return the number of matching message-boards messages that the user has permission to view
17376             * @throws SystemException if a system exception occurred
17377             */
17378            public int filterCountByG_S(long groupId, int status)
17379                    throws SystemException {
17380                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17381                            return countByG_S(groupId, status);
17382                    }
17383    
17384                    StringBundler query = new StringBundler(3);
17385    
17386                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17387    
17388                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
17389    
17390                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
17391    
17392                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17393                                    MBMessage.class.getName(),
17394                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17395    
17396                    Session session = null;
17397    
17398                    try {
17399                            session = openSession();
17400    
17401                            SQLQuery q = session.createSQLQuery(sql);
17402    
17403                            q.addScalar(COUNT_COLUMN_NAME,
17404                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17405    
17406                            QueryPos qPos = QueryPos.getInstance(q);
17407    
17408                            qPos.add(groupId);
17409    
17410                            qPos.add(status);
17411    
17412                            Long count = (Long)q.uniqueResult();
17413    
17414                            return count.intValue();
17415                    }
17416                    catch (Exception e) {
17417                            throw processException(e);
17418                    }
17419                    finally {
17420                            closeSession(session);
17421                    }
17422            }
17423    
17424            /**
17425             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
17426             *
17427             * @param companyId the company ID
17428             * @param status the status
17429             * @return the number of matching message-boards messages
17430             * @throws SystemException if a system exception occurred
17431             */
17432            public int countByC_S(long companyId, int status) throws SystemException {
17433                    Object[] finderArgs = new Object[] { companyId, status };
17434    
17435                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_S,
17436                                    finderArgs, this);
17437    
17438                    if (count == null) {
17439                            StringBundler query = new StringBundler(3);
17440    
17441                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17442    
17443                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
17444    
17445                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
17446    
17447                            String sql = query.toString();
17448    
17449                            Session session = null;
17450    
17451                            try {
17452                                    session = openSession();
17453    
17454                                    Query q = session.createQuery(sql);
17455    
17456                                    QueryPos qPos = QueryPos.getInstance(q);
17457    
17458                                    qPos.add(companyId);
17459    
17460                                    qPos.add(status);
17461    
17462                                    count = (Long)q.uniqueResult();
17463                            }
17464                            catch (Exception e) {
17465                                    throw processException(e);
17466                            }
17467                            finally {
17468                                    if (count == null) {
17469                                            count = Long.valueOf(0);
17470                                    }
17471    
17472                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_S, finderArgs,
17473                                            count);
17474    
17475                                    closeSession(session);
17476                            }
17477                    }
17478    
17479                    return count.intValue();
17480            }
17481    
17482            /**
17483             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
17484             *
17485             * @param userId the user ID
17486             * @param classNameId the class name ID
17487             * @return the number of matching message-boards messages
17488             * @throws SystemException if a system exception occurred
17489             */
17490            public int countByU_C(long userId, long classNameId)
17491                    throws SystemException {
17492                    Object[] finderArgs = new Object[] { userId, classNameId };
17493    
17494                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C,
17495                                    finderArgs, this);
17496    
17497                    if (count == null) {
17498                            StringBundler query = new StringBundler(3);
17499    
17500                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17501    
17502                            query.append(_FINDER_COLUMN_U_C_USERID_2);
17503    
17504                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
17505    
17506                            String sql = query.toString();
17507    
17508                            Session session = null;
17509    
17510                            try {
17511                                    session = openSession();
17512    
17513                                    Query q = session.createQuery(sql);
17514    
17515                                    QueryPos qPos = QueryPos.getInstance(q);
17516    
17517                                    qPos.add(userId);
17518    
17519                                    qPos.add(classNameId);
17520    
17521                                    count = (Long)q.uniqueResult();
17522                            }
17523                            catch (Exception e) {
17524                                    throw processException(e);
17525                            }
17526                            finally {
17527                                    if (count == null) {
17528                                            count = Long.valueOf(0);
17529                                    }
17530    
17531                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C, finderArgs,
17532                                            count);
17533    
17534                                    closeSession(session);
17535                            }
17536                    }
17537    
17538                    return count.intValue();
17539            }
17540    
17541            /**
17542             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
17543             *
17544             * @param userId the user ID
17545             * @param classNameIds the class name IDs
17546             * @return the number of matching message-boards messages
17547             * @throws SystemException if a system exception occurred
17548             */
17549            public int countByU_C(long userId, long[] classNameIds)
17550                    throws SystemException {
17551                    Object[] finderArgs = new Object[] {
17552                                    userId, StringUtil.merge(classNameIds)
17553                            };
17554    
17555                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
17556                                    finderArgs, this);
17557    
17558                    if (count == null) {
17559                            StringBundler query = new StringBundler();
17560    
17561                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17562    
17563                            boolean conjunctionable = false;
17564    
17565                            if (conjunctionable) {
17566                                    query.append(WHERE_AND);
17567                            }
17568    
17569                            query.append(_FINDER_COLUMN_U_C_USERID_5);
17570    
17571                            conjunctionable = true;
17572    
17573                            if ((classNameIds == null) || (classNameIds.length > 0)) {
17574                                    if (conjunctionable) {
17575                                            query.append(WHERE_AND);
17576                                    }
17577    
17578                                    query.append(StringPool.OPEN_PARENTHESIS);
17579    
17580                                    for (int i = 0; i < classNameIds.length; i++) {
17581                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
17582    
17583                                            if ((i + 1) < classNameIds.length) {
17584                                                    query.append(WHERE_OR);
17585                                            }
17586                                    }
17587    
17588                                    query.append(StringPool.CLOSE_PARENTHESIS);
17589    
17590                                    conjunctionable = true;
17591                            }
17592    
17593                            String sql = query.toString();
17594    
17595                            Session session = null;
17596    
17597                            try {
17598                                    session = openSession();
17599    
17600                                    Query q = session.createQuery(sql);
17601    
17602                                    QueryPos qPos = QueryPos.getInstance(q);
17603    
17604                                    qPos.add(userId);
17605    
17606                                    if (classNameIds != null) {
17607                                            qPos.add(classNameIds);
17608                                    }
17609    
17610                                    count = (Long)q.uniqueResult();
17611                            }
17612                            catch (Exception e) {
17613                                    throw processException(e);
17614                            }
17615                            finally {
17616                                    if (count == null) {
17617                                            count = Long.valueOf(0);
17618                                    }
17619    
17620                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
17621                                            finderArgs, count);
17622    
17623                                    closeSession(session);
17624                            }
17625                    }
17626    
17627                    return count.intValue();
17628            }
17629    
17630            /**
17631             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
17632             *
17633             * @param classNameId the class name ID
17634             * @param classPK the class p k
17635             * @return the number of matching message-boards messages
17636             * @throws SystemException if a system exception occurred
17637             */
17638            public int countByC_C(long classNameId, long classPK)
17639                    throws SystemException {
17640                    Object[] finderArgs = new Object[] { classNameId, classPK };
17641    
17642                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
17643                                    finderArgs, this);
17644    
17645                    if (count == null) {
17646                            StringBundler query = new StringBundler(3);
17647    
17648                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17649    
17650                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
17651    
17652                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
17653    
17654                            String sql = query.toString();
17655    
17656                            Session session = null;
17657    
17658                            try {
17659                                    session = openSession();
17660    
17661                                    Query q = session.createQuery(sql);
17662    
17663                                    QueryPos qPos = QueryPos.getInstance(q);
17664    
17665                                    qPos.add(classNameId);
17666    
17667                                    qPos.add(classPK);
17668    
17669                                    count = (Long)q.uniqueResult();
17670                            }
17671                            catch (Exception e) {
17672                                    throw processException(e);
17673                            }
17674                            finally {
17675                                    if (count == null) {
17676                                            count = Long.valueOf(0);
17677                                    }
17678    
17679                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
17680                                            count);
17681    
17682                                    closeSession(session);
17683                            }
17684                    }
17685    
17686                    return count.intValue();
17687            }
17688    
17689            /**
17690             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
17691             *
17692             * @param threadId the thread ID
17693             * @param parentMessageId the parent message ID
17694             * @return the number of matching message-boards messages
17695             * @throws SystemException if a system exception occurred
17696             */
17697            public int countByT_P(long threadId, long parentMessageId)
17698                    throws SystemException {
17699                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
17700    
17701                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_P,
17702                                    finderArgs, this);
17703    
17704                    if (count == null) {
17705                            StringBundler query = new StringBundler(3);
17706    
17707                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17708    
17709                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
17710    
17711                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
17712    
17713                            String sql = query.toString();
17714    
17715                            Session session = null;
17716    
17717                            try {
17718                                    session = openSession();
17719    
17720                                    Query q = session.createQuery(sql);
17721    
17722                                    QueryPos qPos = QueryPos.getInstance(q);
17723    
17724                                    qPos.add(threadId);
17725    
17726                                    qPos.add(parentMessageId);
17727    
17728                                    count = (Long)q.uniqueResult();
17729                            }
17730                            catch (Exception e) {
17731                                    throw processException(e);
17732                            }
17733                            finally {
17734                                    if (count == null) {
17735                                            count = Long.valueOf(0);
17736                                    }
17737    
17738                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_P, finderArgs,
17739                                            count);
17740    
17741                                    closeSession(session);
17742                            }
17743                    }
17744    
17745                    return count.intValue();
17746            }
17747    
17748            /**
17749             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
17750             *
17751             * @param threadId the thread ID
17752             * @param answer the answer
17753             * @return the number of matching message-boards messages
17754             * @throws SystemException if a system exception occurred
17755             */
17756            public int countByT_A(long threadId, boolean answer)
17757                    throws SystemException {
17758                    Object[] finderArgs = new Object[] { threadId, answer };
17759    
17760                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_A,
17761                                    finderArgs, this);
17762    
17763                    if (count == null) {
17764                            StringBundler query = new StringBundler(3);
17765    
17766                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17767    
17768                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
17769    
17770                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
17771    
17772                            String sql = query.toString();
17773    
17774                            Session session = null;
17775    
17776                            try {
17777                                    session = openSession();
17778    
17779                                    Query q = session.createQuery(sql);
17780    
17781                                    QueryPos qPos = QueryPos.getInstance(q);
17782    
17783                                    qPos.add(threadId);
17784    
17785                                    qPos.add(answer);
17786    
17787                                    count = (Long)q.uniqueResult();
17788                            }
17789                            catch (Exception e) {
17790                                    throw processException(e);
17791                            }
17792                            finally {
17793                                    if (count == null) {
17794                                            count = Long.valueOf(0);
17795                                    }
17796    
17797                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_A, finderArgs,
17798                                            count);
17799    
17800                                    closeSession(session);
17801                            }
17802                    }
17803    
17804                    return count.intValue();
17805            }
17806    
17807            /**
17808             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
17809             *
17810             * @param threadId the thread ID
17811             * @param status the status
17812             * @return the number of matching message-boards messages
17813             * @throws SystemException if a system exception occurred
17814             */
17815            public int countByT_S(long threadId, int status) throws SystemException {
17816                    Object[] finderArgs = new Object[] { threadId, status };
17817    
17818                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_S,
17819                                    finderArgs, this);
17820    
17821                    if (count == null) {
17822                            StringBundler query = new StringBundler(3);
17823    
17824                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17825    
17826                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
17827    
17828                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
17829    
17830                            String sql = query.toString();
17831    
17832                            Session session = null;
17833    
17834                            try {
17835                                    session = openSession();
17836    
17837                                    Query q = session.createQuery(sql);
17838    
17839                                    QueryPos qPos = QueryPos.getInstance(q);
17840    
17841                                    qPos.add(threadId);
17842    
17843                                    qPos.add(status);
17844    
17845                                    count = (Long)q.uniqueResult();
17846                            }
17847                            catch (Exception e) {
17848                                    throw processException(e);
17849                            }
17850                            finally {
17851                                    if (count == null) {
17852                                            count = Long.valueOf(0);
17853                                    }
17854    
17855                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_S, finderArgs,
17856                                            count);
17857    
17858                                    closeSession(session);
17859                            }
17860                    }
17861    
17862                    return count.intValue();
17863            }
17864    
17865            /**
17866             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
17867             *
17868             * @param threadId the thread ID
17869             * @param status the status
17870             * @return the number of matching message-boards messages
17871             * @throws SystemException if a system exception occurred
17872             */
17873            public int countByTR_S(long threadId, int status) throws SystemException {
17874                    Object[] finderArgs = new Object[] { threadId, status };
17875    
17876                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TR_S,
17877                                    finderArgs, this);
17878    
17879                    if (count == null) {
17880                            StringBundler query = new StringBundler(3);
17881    
17882                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17883    
17884                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
17885    
17886                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
17887    
17888                            String sql = query.toString();
17889    
17890                            Session session = null;
17891    
17892                            try {
17893                                    session = openSession();
17894    
17895                                    Query q = session.createQuery(sql);
17896    
17897                                    QueryPos qPos = QueryPos.getInstance(q);
17898    
17899                                    qPos.add(threadId);
17900    
17901                                    qPos.add(status);
17902    
17903                                    count = (Long)q.uniqueResult();
17904                            }
17905                            catch (Exception e) {
17906                                    throw processException(e);
17907                            }
17908                            finally {
17909                                    if (count == null) {
17910                                            count = Long.valueOf(0);
17911                                    }
17912    
17913                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TR_S,
17914                                            finderArgs, count);
17915    
17916                                    closeSession(session);
17917                            }
17918                    }
17919    
17920                    return count.intValue();
17921            }
17922    
17923            /**
17924             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
17925             *
17926             * @param groupId the group ID
17927             * @param userId the user ID
17928             * @param status the status
17929             * @return the number of matching message-boards messages
17930             * @throws SystemException if a system exception occurred
17931             */
17932            public int countByG_U_S(long groupId, long userId, int status)
17933                    throws SystemException {
17934                    Object[] finderArgs = new Object[] { groupId, userId, status };
17935    
17936                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_S,
17937                                    finderArgs, this);
17938    
17939                    if (count == null) {
17940                            StringBundler query = new StringBundler(4);
17941    
17942                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17943    
17944                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
17945    
17946                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
17947    
17948                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
17949    
17950                            String sql = query.toString();
17951    
17952                            Session session = null;
17953    
17954                            try {
17955                                    session = openSession();
17956    
17957                                    Query q = session.createQuery(sql);
17958    
17959                                    QueryPos qPos = QueryPos.getInstance(q);
17960    
17961                                    qPos.add(groupId);
17962    
17963                                    qPos.add(userId);
17964    
17965                                    qPos.add(status);
17966    
17967                                    count = (Long)q.uniqueResult();
17968                            }
17969                            catch (Exception e) {
17970                                    throw processException(e);
17971                            }
17972                            finally {
17973                                    if (count == null) {
17974                                            count = Long.valueOf(0);
17975                                    }
17976    
17977                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_S,
17978                                            finderArgs, count);
17979    
17980                                    closeSession(session);
17981                            }
17982                    }
17983    
17984                    return count.intValue();
17985            }
17986    
17987            /**
17988             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
17989             *
17990             * @param groupId the group ID
17991             * @param userId the user ID
17992             * @param status the status
17993             * @return the number of matching message-boards messages that the user has permission to view
17994             * @throws SystemException if a system exception occurred
17995             */
17996            public int filterCountByG_U_S(long groupId, long userId, int status)
17997                    throws SystemException {
17998                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17999                            return countByG_U_S(groupId, userId, status);
18000                    }
18001    
18002                    StringBundler query = new StringBundler(4);
18003    
18004                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18005    
18006                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
18007    
18008                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
18009    
18010                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
18011    
18012                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18013                                    MBMessage.class.getName(),
18014                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18015    
18016                    Session session = null;
18017    
18018                    try {
18019                            session = openSession();
18020    
18021                            SQLQuery q = session.createSQLQuery(sql);
18022    
18023                            q.addScalar(COUNT_COLUMN_NAME,
18024                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18025    
18026                            QueryPos qPos = QueryPos.getInstance(q);
18027    
18028                            qPos.add(groupId);
18029    
18030                            qPos.add(userId);
18031    
18032                            qPos.add(status);
18033    
18034                            Long count = (Long)q.uniqueResult();
18035    
18036                            return count.intValue();
18037                    }
18038                    catch (Exception e) {
18039                            throw processException(e);
18040                    }
18041                    finally {
18042                            closeSession(session);
18043                    }
18044            }
18045    
18046            /**
18047             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
18048             *
18049             * @param groupId the group ID
18050             * @param categoryId the category ID
18051             * @param threadId the thread ID
18052             * @return the number of matching message-boards messages
18053             * @throws SystemException if a system exception occurred
18054             */
18055            public int countByG_C_T(long groupId, long categoryId, long threadId)
18056                    throws SystemException {
18057                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
18058    
18059                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T,
18060                                    finderArgs, this);
18061    
18062                    if (count == null) {
18063                            StringBundler query = new StringBundler(4);
18064    
18065                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18066    
18067                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
18068    
18069                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
18070    
18071                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
18072    
18073                            String sql = query.toString();
18074    
18075                            Session session = null;
18076    
18077                            try {
18078                                    session = openSession();
18079    
18080                                    Query q = session.createQuery(sql);
18081    
18082                                    QueryPos qPos = QueryPos.getInstance(q);
18083    
18084                                    qPos.add(groupId);
18085    
18086                                    qPos.add(categoryId);
18087    
18088                                    qPos.add(threadId);
18089    
18090                                    count = (Long)q.uniqueResult();
18091                            }
18092                            catch (Exception e) {
18093                                    throw processException(e);
18094                            }
18095                            finally {
18096                                    if (count == null) {
18097                                            count = Long.valueOf(0);
18098                                    }
18099    
18100                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T,
18101                                            finderArgs, count);
18102    
18103                                    closeSession(session);
18104                            }
18105                    }
18106    
18107                    return count.intValue();
18108            }
18109    
18110            /**
18111             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
18112             *
18113             * @param groupId the group ID
18114             * @param categoryId the category ID
18115             * @param threadId the thread ID
18116             * @return the number of matching message-boards messages that the user has permission to view
18117             * @throws SystemException if a system exception occurred
18118             */
18119            public int filterCountByG_C_T(long groupId, long categoryId, long threadId)
18120                    throws SystemException {
18121                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18122                            return countByG_C_T(groupId, categoryId, threadId);
18123                    }
18124    
18125                    StringBundler query = new StringBundler(4);
18126    
18127                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18128    
18129                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
18130    
18131                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
18132    
18133                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
18134    
18135                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18136                                    MBMessage.class.getName(),
18137                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18138    
18139                    Session session = null;
18140    
18141                    try {
18142                            session = openSession();
18143    
18144                            SQLQuery q = session.createSQLQuery(sql);
18145    
18146                            q.addScalar(COUNT_COLUMN_NAME,
18147                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18148    
18149                            QueryPos qPos = QueryPos.getInstance(q);
18150    
18151                            qPos.add(groupId);
18152    
18153                            qPos.add(categoryId);
18154    
18155                            qPos.add(threadId);
18156    
18157                            Long count = (Long)q.uniqueResult();
18158    
18159                            return count.intValue();
18160                    }
18161                    catch (Exception e) {
18162                            throw processException(e);
18163                    }
18164                    finally {
18165                            closeSession(session);
18166                    }
18167            }
18168    
18169            /**
18170             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
18171             *
18172             * @param groupId the group ID
18173             * @param categoryId the category ID
18174             * @param status the status
18175             * @return the number of matching message-boards messages
18176             * @throws SystemException if a system exception occurred
18177             */
18178            public int countByG_C_S(long groupId, long categoryId, int status)
18179                    throws SystemException {
18180                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
18181    
18182                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_S,
18183                                    finderArgs, this);
18184    
18185                    if (count == null) {
18186                            StringBundler query = new StringBundler(4);
18187    
18188                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18189    
18190                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
18191    
18192                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
18193    
18194                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
18195    
18196                            String sql = query.toString();
18197    
18198                            Session session = null;
18199    
18200                            try {
18201                                    session = openSession();
18202    
18203                                    Query q = session.createQuery(sql);
18204    
18205                                    QueryPos qPos = QueryPos.getInstance(q);
18206    
18207                                    qPos.add(groupId);
18208    
18209                                    qPos.add(categoryId);
18210    
18211                                    qPos.add(status);
18212    
18213                                    count = (Long)q.uniqueResult();
18214                            }
18215                            catch (Exception e) {
18216                                    throw processException(e);
18217                            }
18218                            finally {
18219                                    if (count == null) {
18220                                            count = Long.valueOf(0);
18221                                    }
18222    
18223                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S,
18224                                            finderArgs, count);
18225    
18226                                    closeSession(session);
18227                            }
18228                    }
18229    
18230                    return count.intValue();
18231            }
18232    
18233            /**
18234             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
18235             *
18236             * @param groupId the group ID
18237             * @param categoryId the category ID
18238             * @param status the status
18239             * @return the number of matching message-boards messages that the user has permission to view
18240             * @throws SystemException if a system exception occurred
18241             */
18242            public int filterCountByG_C_S(long groupId, long categoryId, int status)
18243                    throws SystemException {
18244                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18245                            return countByG_C_S(groupId, categoryId, status);
18246                    }
18247    
18248                    StringBundler query = new StringBundler(4);
18249    
18250                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18251    
18252                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
18253    
18254                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
18255    
18256                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
18257    
18258                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18259                                    MBMessage.class.getName(),
18260                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18261    
18262                    Session session = null;
18263    
18264                    try {
18265                            session = openSession();
18266    
18267                            SQLQuery q = session.createSQLQuery(sql);
18268    
18269                            q.addScalar(COUNT_COLUMN_NAME,
18270                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18271    
18272                            QueryPos qPos = QueryPos.getInstance(q);
18273    
18274                            qPos.add(groupId);
18275    
18276                            qPos.add(categoryId);
18277    
18278                            qPos.add(status);
18279    
18280                            Long count = (Long)q.uniqueResult();
18281    
18282                            return count.intValue();
18283                    }
18284                    catch (Exception e) {
18285                            throw processException(e);
18286                    }
18287                    finally {
18288                            closeSession(session);
18289                    }
18290            }
18291    
18292            /**
18293             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
18294             *
18295             * @param userId the user ID
18296             * @param classNameId the class name ID
18297             * @param classPK the class p k
18298             * @return the number of matching message-boards messages
18299             * @throws SystemException if a system exception occurred
18300             */
18301            public int countByU_C_C(long userId, long classNameId, long classPK)
18302                    throws SystemException {
18303                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
18304    
18305                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C,
18306                                    finderArgs, this);
18307    
18308                    if (count == null) {
18309                            StringBundler query = new StringBundler(4);
18310    
18311                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18312    
18313                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
18314    
18315                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
18316    
18317                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
18318    
18319                            String sql = query.toString();
18320    
18321                            Session session = null;
18322    
18323                            try {
18324                                    session = openSession();
18325    
18326                                    Query q = session.createQuery(sql);
18327    
18328                                    QueryPos qPos = QueryPos.getInstance(q);
18329    
18330                                    qPos.add(userId);
18331    
18332                                    qPos.add(classNameId);
18333    
18334                                    qPos.add(classPK);
18335    
18336                                    count = (Long)q.uniqueResult();
18337                            }
18338                            catch (Exception e) {
18339                                    throw processException(e);
18340                            }
18341                            finally {
18342                                    if (count == null) {
18343                                            count = Long.valueOf(0);
18344                                    }
18345    
18346                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C,
18347                                            finderArgs, count);
18348    
18349                                    closeSession(session);
18350                            }
18351                    }
18352    
18353                    return count.intValue();
18354            }
18355    
18356            /**
18357             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
18358             *
18359             * @param userId the user ID
18360             * @param classNameId the class name ID
18361             * @param status the status
18362             * @return the number of matching message-boards messages
18363             * @throws SystemException if a system exception occurred
18364             */
18365            public int countByU_C_S(long userId, long classNameId, int status)
18366                    throws SystemException {
18367                    Object[] finderArgs = new Object[] { userId, classNameId, status };
18368    
18369                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_S,
18370                                    finderArgs, this);
18371    
18372                    if (count == null) {
18373                            StringBundler query = new StringBundler(4);
18374    
18375                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18376    
18377                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
18378    
18379                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
18380    
18381                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
18382    
18383                            String sql = query.toString();
18384    
18385                            Session session = null;
18386    
18387                            try {
18388                                    session = openSession();
18389    
18390                                    Query q = session.createQuery(sql);
18391    
18392                                    QueryPos qPos = QueryPos.getInstance(q);
18393    
18394                                    qPos.add(userId);
18395    
18396                                    qPos.add(classNameId);
18397    
18398                                    qPos.add(status);
18399    
18400                                    count = (Long)q.uniqueResult();
18401                            }
18402                            catch (Exception e) {
18403                                    throw processException(e);
18404                            }
18405                            finally {
18406                                    if (count == null) {
18407                                            count = Long.valueOf(0);
18408                                    }
18409    
18410                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_S,
18411                                            finderArgs, count);
18412    
18413                                    closeSession(session);
18414                            }
18415                    }
18416    
18417                    return count.intValue();
18418            }
18419    
18420            /**
18421             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
18422             *
18423             * @param userId the user ID
18424             * @param classNameIds the class name IDs
18425             * @param status the status
18426             * @return the number of matching message-boards messages
18427             * @throws SystemException if a system exception occurred
18428             */
18429            public int countByU_C_S(long userId, long[] classNameIds, int status)
18430                    throws SystemException {
18431                    Object[] finderArgs = new Object[] {
18432                                    userId, StringUtil.merge(classNameIds), status
18433                            };
18434    
18435                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
18436                                    finderArgs, this);
18437    
18438                    if (count == null) {
18439                            StringBundler query = new StringBundler();
18440    
18441                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18442    
18443                            boolean conjunctionable = false;
18444    
18445                            if (conjunctionable) {
18446                                    query.append(WHERE_AND);
18447                            }
18448    
18449                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
18450    
18451                            conjunctionable = true;
18452    
18453                            if ((classNameIds == null) || (classNameIds.length > 0)) {
18454                                    if (conjunctionable) {
18455                                            query.append(WHERE_AND);
18456                                    }
18457    
18458                                    query.append(StringPool.OPEN_PARENTHESIS);
18459    
18460                                    for (int i = 0; i < classNameIds.length; i++) {
18461                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
18462    
18463                                            if ((i + 1) < classNameIds.length) {
18464                                                    query.append(WHERE_OR);
18465                                            }
18466                                    }
18467    
18468                                    query.append(StringPool.CLOSE_PARENTHESIS);
18469    
18470                                    conjunctionable = true;
18471                            }
18472    
18473                            if (conjunctionable) {
18474                                    query.append(WHERE_AND);
18475                            }
18476    
18477                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
18478    
18479                            conjunctionable = true;
18480    
18481                            String sql = query.toString();
18482    
18483                            Session session = null;
18484    
18485                            try {
18486                                    session = openSession();
18487    
18488                                    Query q = session.createQuery(sql);
18489    
18490                                    QueryPos qPos = QueryPos.getInstance(q);
18491    
18492                                    qPos.add(userId);
18493    
18494                                    if (classNameIds != null) {
18495                                            qPos.add(classNameIds);
18496                                    }
18497    
18498                                    qPos.add(status);
18499    
18500                                    count = (Long)q.uniqueResult();
18501                            }
18502                            catch (Exception e) {
18503                                    throw processException(e);
18504                            }
18505                            finally {
18506                                    if (count == null) {
18507                                            count = Long.valueOf(0);
18508                                    }
18509    
18510                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
18511                                            finderArgs, count);
18512    
18513                                    closeSession(session);
18514                            }
18515                    }
18516    
18517                    return count.intValue();
18518            }
18519    
18520            /**
18521             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
18522             *
18523             * @param classNameId the class name ID
18524             * @param classPK the class p k
18525             * @param status the status
18526             * @return the number of matching message-boards messages
18527             * @throws SystemException if a system exception occurred
18528             */
18529            public int countByC_C_S(long classNameId, long classPK, int status)
18530                    throws SystemException {
18531                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
18532    
18533                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_S,
18534                                    finderArgs, this);
18535    
18536                    if (count == null) {
18537                            StringBundler query = new StringBundler(4);
18538    
18539                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18540    
18541                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
18542    
18543                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
18544    
18545                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
18546    
18547                            String sql = query.toString();
18548    
18549                            Session session = null;
18550    
18551                            try {
18552                                    session = openSession();
18553    
18554                                    Query q = session.createQuery(sql);
18555    
18556                                    QueryPos qPos = QueryPos.getInstance(q);
18557    
18558                                    qPos.add(classNameId);
18559    
18560                                    qPos.add(classPK);
18561    
18562                                    qPos.add(status);
18563    
18564                                    count = (Long)q.uniqueResult();
18565                            }
18566                            catch (Exception e) {
18567                                    throw processException(e);
18568                            }
18569                            finally {
18570                                    if (count == null) {
18571                                            count = Long.valueOf(0);
18572                                    }
18573    
18574                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_S,
18575                                            finderArgs, count);
18576    
18577                                    closeSession(session);
18578                            }
18579                    }
18580    
18581                    return count.intValue();
18582            }
18583    
18584            /**
18585             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
18586             *
18587             * @param groupId the group ID
18588             * @param categoryId the category ID
18589             * @param threadId the thread ID
18590             * @param answer the answer
18591             * @return the number of matching message-boards messages
18592             * @throws SystemException if a system exception occurred
18593             */
18594            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
18595                    boolean answer) throws SystemException {
18596                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
18597    
18598                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T_A,
18599                                    finderArgs, this);
18600    
18601                    if (count == null) {
18602                            StringBundler query = new StringBundler(5);
18603    
18604                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18605    
18606                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
18607    
18608                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
18609    
18610                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
18611    
18612                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
18613    
18614                            String sql = query.toString();
18615    
18616                            Session session = null;
18617    
18618                            try {
18619                                    session = openSession();
18620    
18621                                    Query q = session.createQuery(sql);
18622    
18623                                    QueryPos qPos = QueryPos.getInstance(q);
18624    
18625                                    qPos.add(groupId);
18626    
18627                                    qPos.add(categoryId);
18628    
18629                                    qPos.add(threadId);
18630    
18631                                    qPos.add(answer);
18632    
18633                                    count = (Long)q.uniqueResult();
18634                            }
18635                            catch (Exception e) {
18636                                    throw processException(e);
18637                            }
18638                            finally {
18639                                    if (count == null) {
18640                                            count = Long.valueOf(0);
18641                                    }
18642    
18643                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T_A,
18644                                            finderArgs, count);
18645    
18646                                    closeSession(session);
18647                            }
18648                    }
18649    
18650                    return count.intValue();
18651            }
18652    
18653            /**
18654             * 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;.
18655             *
18656             * @param groupId the group ID
18657             * @param categoryId the category ID
18658             * @param threadId the thread ID
18659             * @param answer the answer
18660             * @return the number of matching message-boards messages that the user has permission to view
18661             * @throws SystemException if a system exception occurred
18662             */
18663            public int filterCountByG_C_T_A(long groupId, long categoryId,
18664                    long threadId, boolean answer) throws SystemException {
18665                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18666                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
18667                    }
18668    
18669                    StringBundler query = new StringBundler(5);
18670    
18671                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18672    
18673                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
18674    
18675                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
18676    
18677                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
18678    
18679                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
18680    
18681                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18682                                    MBMessage.class.getName(),
18683                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18684    
18685                    Session session = null;
18686    
18687                    try {
18688                            session = openSession();
18689    
18690                            SQLQuery q = session.createSQLQuery(sql);
18691    
18692                            q.addScalar(COUNT_COLUMN_NAME,
18693                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18694    
18695                            QueryPos qPos = QueryPos.getInstance(q);
18696    
18697                            qPos.add(groupId);
18698    
18699                            qPos.add(categoryId);
18700    
18701                            qPos.add(threadId);
18702    
18703                            qPos.add(answer);
18704    
18705                            Long count = (Long)q.uniqueResult();
18706    
18707                            return count.intValue();
18708                    }
18709                    catch (Exception e) {
18710                            throw processException(e);
18711                    }
18712                    finally {
18713                            closeSession(session);
18714                    }
18715            }
18716    
18717            /**
18718             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18719             *
18720             * @param groupId the group ID
18721             * @param categoryId the category ID
18722             * @param threadId the thread ID
18723             * @param status the status
18724             * @return the number of matching message-boards messages
18725             * @throws SystemException if a system exception occurred
18726             */
18727            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
18728                    int status) throws SystemException {
18729                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
18730    
18731                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T_S,
18732                                    finderArgs, this);
18733    
18734                    if (count == null) {
18735                            StringBundler query = new StringBundler(5);
18736    
18737                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18738    
18739                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18740    
18741                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18742    
18743                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18744    
18745                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18746    
18747                            String sql = query.toString();
18748    
18749                            Session session = null;
18750    
18751                            try {
18752                                    session = openSession();
18753    
18754                                    Query q = session.createQuery(sql);
18755    
18756                                    QueryPos qPos = QueryPos.getInstance(q);
18757    
18758                                    qPos.add(groupId);
18759    
18760                                    qPos.add(categoryId);
18761    
18762                                    qPos.add(threadId);
18763    
18764                                    qPos.add(status);
18765    
18766                                    count = (Long)q.uniqueResult();
18767                            }
18768                            catch (Exception e) {
18769                                    throw processException(e);
18770                            }
18771                            finally {
18772                                    if (count == null) {
18773                                            count = Long.valueOf(0);
18774                                    }
18775    
18776                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T_S,
18777                                            finderArgs, count);
18778    
18779                                    closeSession(session);
18780                            }
18781                    }
18782    
18783                    return count.intValue();
18784            }
18785    
18786            /**
18787             * 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;.
18788             *
18789             * @param groupId the group ID
18790             * @param categoryId the category ID
18791             * @param threadId the thread ID
18792             * @param status the status
18793             * @return the number of matching message-boards messages that the user has permission to view
18794             * @throws SystemException if a system exception occurred
18795             */
18796            public int filterCountByG_C_T_S(long groupId, long categoryId,
18797                    long threadId, int status) throws SystemException {
18798                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18799                            return countByG_C_T_S(groupId, categoryId, threadId, status);
18800                    }
18801    
18802                    StringBundler query = new StringBundler(5);
18803    
18804                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18805    
18806                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18807    
18808                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18809    
18810                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18811    
18812                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18813    
18814                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18815                                    MBMessage.class.getName(),
18816                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18817    
18818                    Session session = null;
18819    
18820                    try {
18821                            session = openSession();
18822    
18823                            SQLQuery q = session.createSQLQuery(sql);
18824    
18825                            q.addScalar(COUNT_COLUMN_NAME,
18826                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18827    
18828                            QueryPos qPos = QueryPos.getInstance(q);
18829    
18830                            qPos.add(groupId);
18831    
18832                            qPos.add(categoryId);
18833    
18834                            qPos.add(threadId);
18835    
18836                            qPos.add(status);
18837    
18838                            Long count = (Long)q.uniqueResult();
18839    
18840                            return count.intValue();
18841                    }
18842                    catch (Exception e) {
18843                            throw processException(e);
18844                    }
18845                    finally {
18846                            closeSession(session);
18847                    }
18848            }
18849    
18850            /**
18851             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18852             *
18853             * @param userId the user ID
18854             * @param classNameId the class name ID
18855             * @param classPK the class p k
18856             * @param status the status
18857             * @return the number of matching message-boards messages
18858             * @throws SystemException if a system exception occurred
18859             */
18860            public int countByU_C_C_S(long userId, long classNameId, long classPK,
18861                    int status) throws SystemException {
18862                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
18863    
18864                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C_S,
18865                                    finderArgs, this);
18866    
18867                    if (count == null) {
18868                            StringBundler query = new StringBundler(5);
18869    
18870                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18871    
18872                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18873    
18874                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18875    
18876                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18877    
18878                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18879    
18880                            String sql = query.toString();
18881    
18882                            Session session = null;
18883    
18884                            try {
18885                                    session = openSession();
18886    
18887                                    Query q = session.createQuery(sql);
18888    
18889                                    QueryPos qPos = QueryPos.getInstance(q);
18890    
18891                                    qPos.add(userId);
18892    
18893                                    qPos.add(classNameId);
18894    
18895                                    qPos.add(classPK);
18896    
18897                                    qPos.add(status);
18898    
18899                                    count = (Long)q.uniqueResult();
18900                            }
18901                            catch (Exception e) {
18902                                    throw processException(e);
18903                            }
18904                            finally {
18905                                    if (count == null) {
18906                                            count = Long.valueOf(0);
18907                                    }
18908    
18909                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C_S,
18910                                            finderArgs, count);
18911    
18912                                    closeSession(session);
18913                            }
18914                    }
18915    
18916                    return count.intValue();
18917            }
18918    
18919            /**
18920             * Returns the number of message-boards messages.
18921             *
18922             * @return the number of message-boards messages
18923             * @throws SystemException if a system exception occurred
18924             */
18925            public int countAll() throws SystemException {
18926                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
18927                                    FINDER_ARGS_EMPTY, this);
18928    
18929                    if (count == null) {
18930                            Session session = null;
18931    
18932                            try {
18933                                    session = openSession();
18934    
18935                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
18936    
18937                                    count = (Long)q.uniqueResult();
18938                            }
18939                            catch (Exception e) {
18940                                    throw processException(e);
18941                            }
18942                            finally {
18943                                    if (count == null) {
18944                                            count = Long.valueOf(0);
18945                                    }
18946    
18947                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
18948                                            FINDER_ARGS_EMPTY, count);
18949    
18950                                    closeSession(session);
18951                            }
18952                    }
18953    
18954                    return count.intValue();
18955            }
18956    
18957            /**
18958             * Initializes the message-boards message persistence.
18959             */
18960            public void afterPropertiesSet() {
18961                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
18962                                            com.liferay.portal.util.PropsUtil.get(
18963                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBMessage")));
18964    
18965                    if (listenerClassNames.length > 0) {
18966                            try {
18967                                    List<ModelListener<MBMessage>> listenersList = new ArrayList<ModelListener<MBMessage>>();
18968    
18969                                    for (String listenerClassName : listenerClassNames) {
18970                                            listenersList.add((ModelListener<MBMessage>)InstanceFactory.newInstance(
18971                                                            listenerClassName));
18972                                    }
18973    
18974                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
18975                            }
18976                            catch (Exception e) {
18977                                    _log.error(e);
18978                            }
18979                    }
18980            }
18981    
18982            public void destroy() {
18983                    EntityCacheUtil.removeCache(MBMessageImpl.class.getName());
18984                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
18985                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18986            }
18987    
18988            @BeanReference(type = MBBanPersistence.class)
18989            protected MBBanPersistence mbBanPersistence;
18990            @BeanReference(type = MBCategoryPersistence.class)
18991            protected MBCategoryPersistence mbCategoryPersistence;
18992            @BeanReference(type = MBDiscussionPersistence.class)
18993            protected MBDiscussionPersistence mbDiscussionPersistence;
18994            @BeanReference(type = MBMailingListPersistence.class)
18995            protected MBMailingListPersistence mbMailingListPersistence;
18996            @BeanReference(type = MBMessagePersistence.class)
18997            protected MBMessagePersistence mbMessagePersistence;
18998            @BeanReference(type = MBStatsUserPersistence.class)
18999            protected MBStatsUserPersistence mbStatsUserPersistence;
19000            @BeanReference(type = MBThreadPersistence.class)
19001            protected MBThreadPersistence mbThreadPersistence;
19002            @BeanReference(type = MBThreadFlagPersistence.class)
19003            protected MBThreadFlagPersistence mbThreadFlagPersistence;
19004            @BeanReference(type = CompanyPersistence.class)
19005            protected CompanyPersistence companyPersistence;
19006            @BeanReference(type = GroupPersistence.class)
19007            protected GroupPersistence groupPersistence;
19008            @BeanReference(type = LockPersistence.class)
19009            protected LockPersistence lockPersistence;
19010            @BeanReference(type = PortletPreferencesPersistence.class)
19011            protected PortletPreferencesPersistence portletPreferencesPersistence;
19012            @BeanReference(type = SubscriptionPersistence.class)
19013            protected SubscriptionPersistence subscriptionPersistence;
19014            @BeanReference(type = UserPersistence.class)
19015            protected UserPersistence userPersistence;
19016            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
19017            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
19018            @BeanReference(type = AssetEntryPersistence.class)
19019            protected AssetEntryPersistence assetEntryPersistence;
19020            @BeanReference(type = AssetLinkPersistence.class)
19021            protected AssetLinkPersistence assetLinkPersistence;
19022            @BeanReference(type = AssetTagPersistence.class)
19023            protected AssetTagPersistence assetTagPersistence;
19024            @BeanReference(type = BlogsEntryPersistence.class)
19025            protected BlogsEntryPersistence blogsEntryPersistence;
19026            @BeanReference(type = ExpandoValuePersistence.class)
19027            protected ExpandoValuePersistence expandoValuePersistence;
19028            @BeanReference(type = RatingsStatsPersistence.class)
19029            protected RatingsStatsPersistence ratingsStatsPersistence;
19030            @BeanReference(type = SocialActivityPersistence.class)
19031            protected SocialActivityPersistence socialActivityPersistence;
19032            @BeanReference(type = WikiPagePersistence.class)
19033            protected WikiPagePersistence wikiPagePersistence;
19034            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
19035            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
19036            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
19037            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
19038            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
19039            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
19040            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?)";
19041            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
19042            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
19043            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?) AND ";
19044            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
19045            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMessage.uuid IS NULL AND ";
19046            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMessage.uuid = ? AND ";
19047            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?) AND ";
19048            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMessage.companyId = ?";
19049            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
19050            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
19051            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
19052            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
19053            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
19054            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
19055            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
19056            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
19057            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
19058            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
19059            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
19060            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
19061            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
19062            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
19063            private static final String _FINDER_COLUMN_U_C_USERID_5 = "(" +
19064                    _removeConjunction(_FINDER_COLUMN_U_C_USERID_2) + ")";
19065            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
19066            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_5 = "(" +
19067                    _removeConjunction(_FINDER_COLUMN_U_C_CLASSNAMEID_2) + ")";
19068            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
19069            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
19070            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
19071            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
19072            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
19073            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
19074            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
19075            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
19076            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
19077            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
19078            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
19079            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
19080            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
19081            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
19082            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
19083            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
19084            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
19085            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
19086            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
19087            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
19088            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
19089            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
19090            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
19091            private static final String _FINDER_COLUMN_U_C_S_USERID_5 = "(" +
19092                    _removeConjunction(_FINDER_COLUMN_U_C_S_USERID_2) + ")";
19093            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
19094            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_5 = "(" +
19095                    _removeConjunction(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2) + ")";
19096            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
19097            private static final String _FINDER_COLUMN_U_C_S_STATUS_5 = "(" +
19098                    _removeConjunction(_FINDER_COLUMN_U_C_S_STATUS_2) + ")";
19099            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
19100            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
19101            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
19102            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
19103            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
19104            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
19105            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
19106            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
19107            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
19108            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
19109            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
19110            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
19111            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
19112            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
19113            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
19114    
19115            private static String _removeConjunction(String sql) {
19116                    int pos = sql.indexOf(" AND ");
19117    
19118                    if (pos != -1) {
19119                            sql = sql.substring(0, pos);
19120                    }
19121    
19122                    return sql;
19123            }
19124    
19125            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
19126            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
19127            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
19128                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
19129            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
19130                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
19131            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
19132            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
19133            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
19134            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
19135            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
19136            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
19137            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
19138            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
19139            private static Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
19140            private static MBMessage _nullMBMessage = new MBMessageImpl() {
19141                            @Override
19142                            public Object clone() {
19143                                    return this;
19144                            }
19145    
19146                            @Override
19147                            public CacheModel<MBMessage> toCacheModel() {
19148                                    return _nullMBMessageCacheModel;
19149                            }
19150                    };
19151    
19152            private static CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
19153                            public MBMessage toEntityModel() {
19154                                    return _nullMBMessage;
19155                            }
19156                    };
19157    }