001
014
015 package com.liferay.portlet.messageboards.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.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.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041 import com.liferay.portal.service.persistence.BatchSessionUtil;
042 import com.liferay.portal.service.persistence.CompanyPersistence;
043 import com.liferay.portal.service.persistence.GroupPersistence;
044 import com.liferay.portal.service.persistence.LockPersistence;
045 import com.liferay.portal.service.persistence.PortletPreferencesPersistence;
046 import com.liferay.portal.service.persistence.ResourcePersistence;
047 import com.liferay.portal.service.persistence.SubscriptionPersistence;
048 import com.liferay.portal.service.persistence.UserPersistence;
049 import com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence;
050 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
051
052 import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
053 import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
054 import com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence;
055 import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
056 import com.liferay.portlet.messageboards.NoSuchMessageException;
057 import com.liferay.portlet.messageboards.model.MBMessage;
058 import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
059 import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
060 import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
061 import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
062 import com.liferay.portlet.social.service.persistence.SocialEquityLogPersistence;
063
064 import java.io.Serializable;
065
066 import java.util.ArrayList;
067 import java.util.Collections;
068 import java.util.List;
069
070
086 public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
087 implements MBMessagePersistence {
088 public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
089 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
090 ".List";
091 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
092 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
093 "findByUuid",
094 new String[] {
095 String.class.getName(),
096
097 "java.lang.Integer", "java.lang.Integer",
098 "com.liferay.portal.kernel.util.OrderByComparator"
099 });
100 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
101 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
102 "countByUuid", new String[] { String.class.getName() });
103 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
104 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
105 "fetchByUUID_G",
106 new String[] { String.class.getName(), Long.class.getName() });
107 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
108 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
109 "countByUUID_G",
110 new String[] { String.class.getName(), Long.class.getName() });
111 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
112 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
113 "findByGroupId",
114 new String[] {
115 Long.class.getName(),
116
117 "java.lang.Integer", "java.lang.Integer",
118 "com.liferay.portal.kernel.util.OrderByComparator"
119 });
120 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
121 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
122 "countByGroupId", new String[] { Long.class.getName() });
123 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
124 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
125 "findByCompanyId",
126 new String[] {
127 Long.class.getName(),
128
129 "java.lang.Integer", "java.lang.Integer",
130 "com.liferay.portal.kernel.util.OrderByComparator"
131 });
132 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
133 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
134 "countByCompanyId", new String[] { Long.class.getName() });
135 public static final FinderPath FINDER_PATH_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
136 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
137 "findByThreadId",
138 new String[] {
139 Long.class.getName(),
140
141 "java.lang.Integer", "java.lang.Integer",
142 "com.liferay.portal.kernel.util.OrderByComparator"
143 });
144 public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
145 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
146 "countByThreadId", new String[] { Long.class.getName() });
147 public static final FinderPath FINDER_PATH_FIND_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
148 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
149 "findByThreadReplies",
150 new String[] {
151 Long.class.getName(),
152
153 "java.lang.Integer", "java.lang.Integer",
154 "com.liferay.portal.kernel.util.OrderByComparator"
155 });
156 public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
157 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
158 "countByThreadReplies", new String[] { Long.class.getName() });
159 public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
160 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
161 "findByUserId",
162 new String[] {
163 Long.class.getName(),
164
165 "java.lang.Integer", "java.lang.Integer",
166 "com.liferay.portal.kernel.util.OrderByComparator"
167 });
168 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
169 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
170 "countByUserId", new String[] { Long.class.getName() });
171 public static final FinderPath FINDER_PATH_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
172 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
173 "findByG_U",
174 new String[] {
175 Long.class.getName(), Long.class.getName(),
176
177 "java.lang.Integer", "java.lang.Integer",
178 "com.liferay.portal.kernel.util.OrderByComparator"
179 });
180 public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
181 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
182 "countByG_U",
183 new String[] { Long.class.getName(), Long.class.getName() });
184 public static final FinderPath FINDER_PATH_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
185 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
186 "findByG_C",
187 new String[] {
188 Long.class.getName(), Long.class.getName(),
189
190 "java.lang.Integer", "java.lang.Integer",
191 "com.liferay.portal.kernel.util.OrderByComparator"
192 });
193 public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
194 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
195 "countByG_C",
196 new String[] { Long.class.getName(), Long.class.getName() });
197 public static final FinderPath FINDER_PATH_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
198 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
199 "findByG_S",
200 new String[] {
201 Long.class.getName(), Integer.class.getName(),
202
203 "java.lang.Integer", "java.lang.Integer",
204 "com.liferay.portal.kernel.util.OrderByComparator"
205 });
206 public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
207 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
208 "countByG_S",
209 new String[] { Long.class.getName(), Integer.class.getName() });
210 public static final FinderPath FINDER_PATH_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
211 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
212 "findByC_S",
213 new String[] {
214 Long.class.getName(), Integer.class.getName(),
215
216 "java.lang.Integer", "java.lang.Integer",
217 "com.liferay.portal.kernel.util.OrderByComparator"
218 });
219 public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
220 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
221 "countByC_S",
222 new String[] { Long.class.getName(), Integer.class.getName() });
223 public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
224 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
225 "findByC_C",
226 new String[] {
227 Long.class.getName(), Long.class.getName(),
228
229 "java.lang.Integer", "java.lang.Integer",
230 "com.liferay.portal.kernel.util.OrderByComparator"
231 });
232 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
233 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
234 "countByC_C",
235 new String[] { Long.class.getName(), Long.class.getName() });
236 public static final FinderPath FINDER_PATH_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
237 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
238 "findByT_P",
239 new String[] {
240 Long.class.getName(), Long.class.getName(),
241
242 "java.lang.Integer", "java.lang.Integer",
243 "com.liferay.portal.kernel.util.OrderByComparator"
244 });
245 public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
246 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
247 "countByT_P",
248 new String[] { Long.class.getName(), Long.class.getName() });
249 public static final FinderPath FINDER_PATH_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
250 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
251 "findByT_S",
252 new String[] {
253 Long.class.getName(), Integer.class.getName(),
254
255 "java.lang.Integer", "java.lang.Integer",
256 "com.liferay.portal.kernel.util.OrderByComparator"
257 });
258 public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
259 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
260 "countByT_S",
261 new String[] { Long.class.getName(), Integer.class.getName() });
262 public static final FinderPath FINDER_PATH_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
263 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
264 "findByTR_S",
265 new String[] {
266 Long.class.getName(), Integer.class.getName(),
267
268 "java.lang.Integer", "java.lang.Integer",
269 "com.liferay.portal.kernel.util.OrderByComparator"
270 });
271 public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
272 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
273 "countByTR_S",
274 new String[] { Long.class.getName(), Integer.class.getName() });
275 public static final FinderPath FINDER_PATH_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
276 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
277 "findByG_U_S",
278 new String[] {
279 Long.class.getName(), Long.class.getName(),
280 Integer.class.getName(),
281
282 "java.lang.Integer", "java.lang.Integer",
283 "com.liferay.portal.kernel.util.OrderByComparator"
284 });
285 public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
286 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
287 "countByG_U_S",
288 new String[] {
289 Long.class.getName(), Long.class.getName(),
290 Integer.class.getName()
291 });
292 public static final FinderPath FINDER_PATH_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
293 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
294 "findByG_C_T",
295 new String[] {
296 Long.class.getName(), Long.class.getName(), Long.class.getName(),
297
298 "java.lang.Integer", "java.lang.Integer",
299 "com.liferay.portal.kernel.util.OrderByComparator"
300 });
301 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
302 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
303 "countByG_C_T",
304 new String[] {
305 Long.class.getName(), Long.class.getName(), Long.class.getName()
306 });
307 public static final FinderPath FINDER_PATH_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
308 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
309 "findByG_C_S",
310 new String[] {
311 Long.class.getName(), Long.class.getName(),
312 Integer.class.getName(),
313
314 "java.lang.Integer", "java.lang.Integer",
315 "com.liferay.portal.kernel.util.OrderByComparator"
316 });
317 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
318 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
319 "countByG_C_S",
320 new String[] {
321 Long.class.getName(), Long.class.getName(),
322 Integer.class.getName()
323 });
324 public static final FinderPath FINDER_PATH_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
325 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
326 "findByC_C_S",
327 new String[] {
328 Long.class.getName(), Long.class.getName(),
329 Integer.class.getName(),
330
331 "java.lang.Integer", "java.lang.Integer",
332 "com.liferay.portal.kernel.util.OrderByComparator"
333 });
334 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
335 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
336 "countByC_C_S",
337 new String[] {
338 Long.class.getName(), Long.class.getName(),
339 Integer.class.getName()
340 });
341 public static final FinderPath FINDER_PATH_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
342 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
343 "findByG_C_T_S",
344 new String[] {
345 Long.class.getName(), Long.class.getName(), Long.class.getName(),
346 Integer.class.getName(),
347
348 "java.lang.Integer", "java.lang.Integer",
349 "com.liferay.portal.kernel.util.OrderByComparator"
350 });
351 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
352 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
353 "countByG_C_T_S",
354 new String[] {
355 Long.class.getName(), Long.class.getName(), Long.class.getName(),
356 Integer.class.getName()
357 });
358 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
359 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
360 "findAll", new String[0]);
361 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
362 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
363 "countAll", new String[0]);
364
365
370 public void cacheResult(MBMessage mbMessage) {
371 EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
372 MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
373
374 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
375 new Object[] { mbMessage.getUuid(), new Long(mbMessage.getGroupId()) },
376 mbMessage);
377 }
378
379
384 public void cacheResult(List<MBMessage> mbMessages) {
385 for (MBMessage mbMessage : mbMessages) {
386 if (EntityCacheUtil.getResult(
387 MBMessageModelImpl.ENTITY_CACHE_ENABLED,
388 MBMessageImpl.class, mbMessage.getPrimaryKey(), this) == null) {
389 cacheResult(mbMessage);
390 }
391 }
392 }
393
394
401 public void clearCache() {
402 CacheRegistryUtil.clear(MBMessageImpl.class.getName());
403 EntityCacheUtil.clearCache(MBMessageImpl.class.getName());
404 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
405 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
406 }
407
408
415 public void clearCache(MBMessage mbMessage) {
416 EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
417 MBMessageImpl.class, mbMessage.getPrimaryKey());
418
419 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
420 new Object[] { mbMessage.getUuid(), new Long(mbMessage.getGroupId()) });
421 }
422
423
429 public MBMessage create(long messageId) {
430 MBMessage mbMessage = new MBMessageImpl();
431
432 mbMessage.setNew(true);
433 mbMessage.setPrimaryKey(messageId);
434
435 String uuid = PortalUUIDUtil.generate();
436
437 mbMessage.setUuid(uuid);
438
439 return mbMessage;
440 }
441
442
450 public MBMessage remove(Serializable primaryKey)
451 throws NoSuchModelException, SystemException {
452 return remove(((Long)primaryKey).longValue());
453 }
454
455
463 public MBMessage remove(long messageId)
464 throws NoSuchMessageException, SystemException {
465 Session session = null;
466
467 try {
468 session = openSession();
469
470 MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
471 new Long(messageId));
472
473 if (mbMessage == null) {
474 if (_log.isWarnEnabled()) {
475 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageId);
476 }
477
478 throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
479 messageId);
480 }
481
482 return remove(mbMessage);
483 }
484 catch (NoSuchMessageException nsee) {
485 throw nsee;
486 }
487 catch (Exception e) {
488 throw processException(e);
489 }
490 finally {
491 closeSession(session);
492 }
493 }
494
495 protected MBMessage removeImpl(MBMessage mbMessage)
496 throws SystemException {
497 mbMessage = toUnwrappedModel(mbMessage);
498
499 Session session = null;
500
501 try {
502 session = openSession();
503
504 BatchSessionUtil.delete(session, mbMessage);
505 }
506 catch (Exception e) {
507 throw processException(e);
508 }
509 finally {
510 closeSession(session);
511 }
512
513 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
514
515 MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
516
517 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
518 new Object[] {
519 mbMessageModelImpl.getUuid(),
520 new Long(mbMessageModelImpl.getGroupId())
521 });
522
523 EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
524 MBMessageImpl.class, mbMessage.getPrimaryKey());
525
526 return mbMessage;
527 }
528
529 public MBMessage updateImpl(
530 com.liferay.portlet.messageboards.model.MBMessage mbMessage,
531 boolean merge) throws SystemException {
532 mbMessage = toUnwrappedModel(mbMessage);
533
534 boolean isNew = mbMessage.isNew();
535
536 MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
537
538 if (Validator.isNull(mbMessage.getUuid())) {
539 String uuid = PortalUUIDUtil.generate();
540
541 mbMessage.setUuid(uuid);
542 }
543
544 Session session = null;
545
546 try {
547 session = openSession();
548
549 BatchSessionUtil.update(session, mbMessage, merge);
550
551 mbMessage.setNew(false);
552 }
553 catch (Exception e) {
554 throw processException(e);
555 }
556 finally {
557 closeSession(session);
558 }
559
560 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
561
562 EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
563 MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
564
565 if (!isNew &&
566 (!Validator.equals(mbMessage.getUuid(),
567 mbMessageModelImpl.getOriginalUuid()) ||
568 (mbMessage.getGroupId() != mbMessageModelImpl.getOriginalGroupId()))) {
569 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
570 new Object[] {
571 mbMessageModelImpl.getOriginalUuid(),
572 new Long(mbMessageModelImpl.getOriginalGroupId())
573 });
574 }
575
576 if (isNew ||
577 (!Validator.equals(mbMessage.getUuid(),
578 mbMessageModelImpl.getOriginalUuid()) ||
579 (mbMessage.getGroupId() != mbMessageModelImpl.getOriginalGroupId()))) {
580 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
581 new Object[] {
582 mbMessage.getUuid(), new Long(mbMessage.getGroupId())
583 }, mbMessage);
584 }
585
586 return mbMessage;
587 }
588
589 protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
590 if (mbMessage instanceof MBMessageImpl) {
591 return mbMessage;
592 }
593
594 MBMessageImpl mbMessageImpl = new MBMessageImpl();
595
596 mbMessageImpl.setNew(mbMessage.isNew());
597 mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
598
599 mbMessageImpl.setUuid(mbMessage.getUuid());
600 mbMessageImpl.setMessageId(mbMessage.getMessageId());
601 mbMessageImpl.setGroupId(mbMessage.getGroupId());
602 mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
603 mbMessageImpl.setUserId(mbMessage.getUserId());
604 mbMessageImpl.setUserName(mbMessage.getUserName());
605 mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
606 mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
607 mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
608 mbMessageImpl.setClassPK(mbMessage.getClassPK());
609 mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
610 mbMessageImpl.setThreadId(mbMessage.getThreadId());
611 mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
612 mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
613 mbMessageImpl.setSubject(mbMessage.getSubject());
614 mbMessageImpl.setBody(mbMessage.getBody());
615 mbMessageImpl.setAttachments(mbMessage.isAttachments());
616 mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
617 mbMessageImpl.setPriority(mbMessage.getPriority());
618 mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
619 mbMessageImpl.setStatus(mbMessage.getStatus());
620 mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
621 mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
622 mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
623
624 return mbMessageImpl;
625 }
626
627
635 public MBMessage findByPrimaryKey(Serializable primaryKey)
636 throws NoSuchModelException, SystemException {
637 return findByPrimaryKey(((Long)primaryKey).longValue());
638 }
639
640
648 public MBMessage findByPrimaryKey(long messageId)
649 throws NoSuchMessageException, SystemException {
650 MBMessage mbMessage = fetchByPrimaryKey(messageId);
651
652 if (mbMessage == null) {
653 if (_log.isWarnEnabled()) {
654 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageId);
655 }
656
657 throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
658 messageId);
659 }
660
661 return mbMessage;
662 }
663
664
671 public MBMessage fetchByPrimaryKey(Serializable primaryKey)
672 throws SystemException {
673 return fetchByPrimaryKey(((Long)primaryKey).longValue());
674 }
675
676
683 public MBMessage fetchByPrimaryKey(long messageId)
684 throws SystemException {
685 MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
686 MBMessageImpl.class, messageId, this);
687
688 if (mbMessage == null) {
689 Session session = null;
690
691 try {
692 session = openSession();
693
694 mbMessage = (MBMessage)session.get(MBMessageImpl.class,
695 new Long(messageId));
696 }
697 catch (Exception e) {
698 throw processException(e);
699 }
700 finally {
701 if (mbMessage != null) {
702 cacheResult(mbMessage);
703 }
704
705 closeSession(session);
706 }
707 }
708
709 return mbMessage;
710 }
711
712
719 public List<MBMessage> findByUuid(String uuid) throws SystemException {
720 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
721 }
722
723
736 public List<MBMessage> findByUuid(String uuid, int start, int end)
737 throws SystemException {
738 return findByUuid(uuid, start, end, null);
739 }
740
741
755 public List<MBMessage> findByUuid(String uuid, int start, int end,
756 OrderByComparator orderByComparator) throws SystemException {
757 Object[] finderArgs = new Object[] {
758 uuid,
759
760 String.valueOf(start), String.valueOf(end),
761 String.valueOf(orderByComparator)
762 };
763
764 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
765 finderArgs, this);
766
767 if (list == null) {
768 StringBundler query = null;
769
770 if (orderByComparator != null) {
771 query = new StringBundler(3 +
772 (orderByComparator.getOrderByFields().length * 3));
773 }
774 else {
775 query = new StringBundler(3);
776 }
777
778 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
779
780 if (uuid == null) {
781 query.append(_FINDER_COLUMN_UUID_UUID_1);
782 }
783 else {
784 if (uuid.equals(StringPool.BLANK)) {
785 query.append(_FINDER_COLUMN_UUID_UUID_3);
786 }
787 else {
788 query.append(_FINDER_COLUMN_UUID_UUID_2);
789 }
790 }
791
792 if (orderByComparator != null) {
793 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
794 orderByComparator);
795 }
796
797 else {
798 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
799 }
800
801 String sql = query.toString();
802
803 Session session = null;
804
805 try {
806 session = openSession();
807
808 Query q = session.createQuery(sql);
809
810 QueryPos qPos = QueryPos.getInstance(q);
811
812 if (uuid != null) {
813 qPos.add(uuid);
814 }
815
816 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
817 end);
818 }
819 catch (Exception e) {
820 throw processException(e);
821 }
822 finally {
823 if (list == null) {
824 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_UUID,
825 finderArgs);
826 }
827 else {
828 cacheResult(list);
829
830 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID,
831 finderArgs, list);
832 }
833
834 closeSession(session);
835 }
836 }
837
838 return list;
839 }
840
841
854 public MBMessage findByUuid_First(String uuid,
855 OrderByComparator orderByComparator)
856 throws NoSuchMessageException, SystemException {
857 List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
858
859 if (list.isEmpty()) {
860 StringBundler msg = new StringBundler(4);
861
862 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
863
864 msg.append("uuid=");
865 msg.append(uuid);
866
867 msg.append(StringPool.CLOSE_CURLY_BRACE);
868
869 throw new NoSuchMessageException(msg.toString());
870 }
871 else {
872 return list.get(0);
873 }
874 }
875
876
889 public MBMessage findByUuid_Last(String uuid,
890 OrderByComparator orderByComparator)
891 throws NoSuchMessageException, SystemException {
892 int count = countByUuid(uuid);
893
894 List<MBMessage> list = findByUuid(uuid, count - 1, count,
895 orderByComparator);
896
897 if (list.isEmpty()) {
898 StringBundler msg = new StringBundler(4);
899
900 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
901
902 msg.append("uuid=");
903 msg.append(uuid);
904
905 msg.append(StringPool.CLOSE_CURLY_BRACE);
906
907 throw new NoSuchMessageException(msg.toString());
908 }
909 else {
910 return list.get(0);
911 }
912 }
913
914
928 public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
929 OrderByComparator orderByComparator)
930 throws NoSuchMessageException, SystemException {
931 MBMessage mbMessage = findByPrimaryKey(messageId);
932
933 Session session = null;
934
935 try {
936 session = openSession();
937
938 MBMessage[] array = new MBMessageImpl[3];
939
940 array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
941 orderByComparator, true);
942
943 array[1] = mbMessage;
944
945 array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
946 orderByComparator, false);
947
948 return array;
949 }
950 catch (Exception e) {
951 throw processException(e);
952 }
953 finally {
954 closeSession(session);
955 }
956 }
957
958 protected MBMessage getByUuid_PrevAndNext(Session session,
959 MBMessage mbMessage, String uuid, OrderByComparator orderByComparator,
960 boolean previous) {
961 StringBundler query = null;
962
963 if (orderByComparator != null) {
964 query = new StringBundler(6 +
965 (orderByComparator.getOrderByFields().length * 6));
966 }
967 else {
968 query = new StringBundler(3);
969 }
970
971 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
972
973 if (uuid == null) {
974 query.append(_FINDER_COLUMN_UUID_UUID_1);
975 }
976 else {
977 if (uuid.equals(StringPool.BLANK)) {
978 query.append(_FINDER_COLUMN_UUID_UUID_3);
979 }
980 else {
981 query.append(_FINDER_COLUMN_UUID_UUID_2);
982 }
983 }
984
985 if (orderByComparator != null) {
986 String[] orderByFields = orderByComparator.getOrderByFields();
987
988 if (orderByFields.length > 0) {
989 query.append(WHERE_AND);
990 }
991
992 for (int i = 0; i < orderByFields.length; i++) {
993 query.append(_ORDER_BY_ENTITY_ALIAS);
994 query.append(orderByFields[i]);
995
996 if ((i + 1) < orderByFields.length) {
997 if (orderByComparator.isAscending() ^ previous) {
998 query.append(WHERE_GREATER_THAN_HAS_NEXT);
999 }
1000 else {
1001 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1002 }
1003 }
1004 else {
1005 if (orderByComparator.isAscending() ^ previous) {
1006 query.append(WHERE_GREATER_THAN);
1007 }
1008 else {
1009 query.append(WHERE_LESSER_THAN);
1010 }
1011 }
1012 }
1013
1014 query.append(ORDER_BY_CLAUSE);
1015
1016 for (int i = 0; i < orderByFields.length; i++) {
1017 query.append(_ORDER_BY_ENTITY_ALIAS);
1018 query.append(orderByFields[i]);
1019
1020 if ((i + 1) < orderByFields.length) {
1021 if (orderByComparator.isAscending() ^ previous) {
1022 query.append(ORDER_BY_ASC_HAS_NEXT);
1023 }
1024 else {
1025 query.append(ORDER_BY_DESC_HAS_NEXT);
1026 }
1027 }
1028 else {
1029 if (orderByComparator.isAscending() ^ previous) {
1030 query.append(ORDER_BY_ASC);
1031 }
1032 else {
1033 query.append(ORDER_BY_DESC);
1034 }
1035 }
1036 }
1037 }
1038
1039 else {
1040 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1041 }
1042
1043 String sql = query.toString();
1044
1045 Query q = session.createQuery(sql);
1046
1047 q.setFirstResult(0);
1048 q.setMaxResults(2);
1049
1050 QueryPos qPos = QueryPos.getInstance(q);
1051
1052 if (uuid != null) {
1053 qPos.add(uuid);
1054 }
1055
1056 if (orderByComparator != null) {
1057 Object[] values = orderByComparator.getOrderByValues(mbMessage);
1058
1059 for (Object value : values) {
1060 qPos.add(value);
1061 }
1062 }
1063
1064 List<MBMessage> list = q.list();
1065
1066 if (list.size() == 2) {
1067 return list.get(1);
1068 }
1069 else {
1070 return null;
1071 }
1072 }
1073
1074
1083 public MBMessage findByUUID_G(String uuid, long groupId)
1084 throws NoSuchMessageException, SystemException {
1085 MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
1086
1087 if (mbMessage == null) {
1088 StringBundler msg = new StringBundler(6);
1089
1090 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1091
1092 msg.append("uuid=");
1093 msg.append(uuid);
1094
1095 msg.append(", groupId=");
1096 msg.append(groupId);
1097
1098 msg.append(StringPool.CLOSE_CURLY_BRACE);
1099
1100 if (_log.isWarnEnabled()) {
1101 _log.warn(msg.toString());
1102 }
1103
1104 throw new NoSuchMessageException(msg.toString());
1105 }
1106
1107 return mbMessage;
1108 }
1109
1110
1118 public MBMessage fetchByUUID_G(String uuid, long groupId)
1119 throws SystemException {
1120 return fetchByUUID_G(uuid, groupId, true);
1121 }
1122
1123
1131 public MBMessage fetchByUUID_G(String uuid, long groupId,
1132 boolean retrieveFromCache) throws SystemException {
1133 Object[] finderArgs = new Object[] { uuid, groupId };
1134
1135 Object result = null;
1136
1137 if (retrieveFromCache) {
1138 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1139 finderArgs, this);
1140 }
1141
1142 if (result == null) {
1143 StringBundler query = new StringBundler(4);
1144
1145 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1146
1147 if (uuid == null) {
1148 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1149 }
1150 else {
1151 if (uuid.equals(StringPool.BLANK)) {
1152 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1153 }
1154 else {
1155 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1156 }
1157 }
1158
1159 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1160
1161 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1162
1163 String sql = query.toString();
1164
1165 Session session = null;
1166
1167 try {
1168 session = openSession();
1169
1170 Query q = session.createQuery(sql);
1171
1172 QueryPos qPos = QueryPos.getInstance(q);
1173
1174 if (uuid != null) {
1175 qPos.add(uuid);
1176 }
1177
1178 qPos.add(groupId);
1179
1180 List<MBMessage> list = q.list();
1181
1182 result = list;
1183
1184 MBMessage mbMessage = null;
1185
1186 if (list.isEmpty()) {
1187 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1188 finderArgs, list);
1189 }
1190 else {
1191 mbMessage = list.get(0);
1192
1193 cacheResult(mbMessage);
1194
1195 if ((mbMessage.getUuid() == null) ||
1196 !mbMessage.getUuid().equals(uuid) ||
1197 (mbMessage.getGroupId() != groupId)) {
1198 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1199 finderArgs, mbMessage);
1200 }
1201 }
1202
1203 return mbMessage;
1204 }
1205 catch (Exception e) {
1206 throw processException(e);
1207 }
1208 finally {
1209 if (result == null) {
1210 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1211 finderArgs);
1212 }
1213
1214 closeSession(session);
1215 }
1216 }
1217 else {
1218 if (result instanceof List<?>) {
1219 return null;
1220 }
1221 else {
1222 return (MBMessage)result;
1223 }
1224 }
1225 }
1226
1227
1234 public List<MBMessage> findByGroupId(long groupId)
1235 throws SystemException {
1236 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1237 }
1238
1239
1252 public List<MBMessage> findByGroupId(long groupId, int start, int end)
1253 throws SystemException {
1254 return findByGroupId(groupId, start, end, null);
1255 }
1256
1257
1271 public List<MBMessage> findByGroupId(long groupId, int start, int end,
1272 OrderByComparator orderByComparator) throws SystemException {
1273 Object[] finderArgs = new Object[] {
1274 groupId,
1275
1276 String.valueOf(start), String.valueOf(end),
1277 String.valueOf(orderByComparator)
1278 };
1279
1280 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1281 finderArgs, this);
1282
1283 if (list == null) {
1284 StringBundler query = null;
1285
1286 if (orderByComparator != null) {
1287 query = new StringBundler(3 +
1288 (orderByComparator.getOrderByFields().length * 3));
1289 }
1290 else {
1291 query = new StringBundler(3);
1292 }
1293
1294 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1295
1296 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1297
1298 if (orderByComparator != null) {
1299 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1300 orderByComparator);
1301 }
1302
1303 else {
1304 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1305 }
1306
1307 String sql = query.toString();
1308
1309 Session session = null;
1310
1311 try {
1312 session = openSession();
1313
1314 Query q = session.createQuery(sql);
1315
1316 QueryPos qPos = QueryPos.getInstance(q);
1317
1318 qPos.add(groupId);
1319
1320 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
1321 end);
1322 }
1323 catch (Exception e) {
1324 throw processException(e);
1325 }
1326 finally {
1327 if (list == null) {
1328 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_GROUPID,
1329 finderArgs);
1330 }
1331 else {
1332 cacheResult(list);
1333
1334 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1335 finderArgs, list);
1336 }
1337
1338 closeSession(session);
1339 }
1340 }
1341
1342 return list;
1343 }
1344
1345
1358 public MBMessage findByGroupId_First(long groupId,
1359 OrderByComparator orderByComparator)
1360 throws NoSuchMessageException, SystemException {
1361 List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1362
1363 if (list.isEmpty()) {
1364 StringBundler msg = new StringBundler(4);
1365
1366 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1367
1368 msg.append("groupId=");
1369 msg.append(groupId);
1370
1371 msg.append(StringPool.CLOSE_CURLY_BRACE);
1372
1373 throw new NoSuchMessageException(msg.toString());
1374 }
1375 else {
1376 return list.get(0);
1377 }
1378 }
1379
1380
1393 public MBMessage findByGroupId_Last(long groupId,
1394 OrderByComparator orderByComparator)
1395 throws NoSuchMessageException, SystemException {
1396 int count = countByGroupId(groupId);
1397
1398 List<MBMessage> list = findByGroupId(groupId, count - 1, count,
1399 orderByComparator);
1400
1401 if (list.isEmpty()) {
1402 StringBundler msg = new StringBundler(4);
1403
1404 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1405
1406 msg.append("groupId=");
1407 msg.append(groupId);
1408
1409 msg.append(StringPool.CLOSE_CURLY_BRACE);
1410
1411 throw new NoSuchMessageException(msg.toString());
1412 }
1413 else {
1414 return list.get(0);
1415 }
1416 }
1417
1418
1432 public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
1433 OrderByComparator orderByComparator)
1434 throws NoSuchMessageException, SystemException {
1435 MBMessage mbMessage = findByPrimaryKey(messageId);
1436
1437 Session session = null;
1438
1439 try {
1440 session = openSession();
1441
1442 MBMessage[] array = new MBMessageImpl[3];
1443
1444 array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1445 orderByComparator, true);
1446
1447 array[1] = mbMessage;
1448
1449 array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1450 orderByComparator, false);
1451
1452 return array;
1453 }
1454 catch (Exception e) {
1455 throw processException(e);
1456 }
1457 finally {
1458 closeSession(session);
1459 }
1460 }
1461
1462 protected MBMessage getByGroupId_PrevAndNext(Session session,
1463 MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
1464 boolean previous) {
1465 StringBundler query = null;
1466
1467 if (orderByComparator != null) {
1468 query = new StringBundler(6 +
1469 (orderByComparator.getOrderByFields().length * 6));
1470 }
1471 else {
1472 query = new StringBundler(3);
1473 }
1474
1475 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1476
1477 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1478
1479 if (orderByComparator != null) {
1480 String[] orderByFields = orderByComparator.getOrderByFields();
1481
1482 if (orderByFields.length > 0) {
1483 query.append(WHERE_AND);
1484 }
1485
1486 for (int i = 0; i < orderByFields.length; i++) {
1487 query.append(_ORDER_BY_ENTITY_ALIAS);
1488 query.append(orderByFields[i]);
1489
1490 if ((i + 1) < orderByFields.length) {
1491 if (orderByComparator.isAscending() ^ previous) {
1492 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1493 }
1494 else {
1495 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1496 }
1497 }
1498 else {
1499 if (orderByComparator.isAscending() ^ previous) {
1500 query.append(WHERE_GREATER_THAN);
1501 }
1502 else {
1503 query.append(WHERE_LESSER_THAN);
1504 }
1505 }
1506 }
1507
1508 query.append(ORDER_BY_CLAUSE);
1509
1510 for (int i = 0; i < orderByFields.length; i++) {
1511 query.append(_ORDER_BY_ENTITY_ALIAS);
1512 query.append(orderByFields[i]);
1513
1514 if ((i + 1) < orderByFields.length) {
1515 if (orderByComparator.isAscending() ^ previous) {
1516 query.append(ORDER_BY_ASC_HAS_NEXT);
1517 }
1518 else {
1519 query.append(ORDER_BY_DESC_HAS_NEXT);
1520 }
1521 }
1522 else {
1523 if (orderByComparator.isAscending() ^ previous) {
1524 query.append(ORDER_BY_ASC);
1525 }
1526 else {
1527 query.append(ORDER_BY_DESC);
1528 }
1529 }
1530 }
1531 }
1532
1533 else {
1534 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1535 }
1536
1537 String sql = query.toString();
1538
1539 Query q = session.createQuery(sql);
1540
1541 q.setFirstResult(0);
1542 q.setMaxResults(2);
1543
1544 QueryPos qPos = QueryPos.getInstance(q);
1545
1546 qPos.add(groupId);
1547
1548 if (orderByComparator != null) {
1549 Object[] values = orderByComparator.getOrderByValues(mbMessage);
1550
1551 for (Object value : values) {
1552 qPos.add(value);
1553 }
1554 }
1555
1556 List<MBMessage> list = q.list();
1557
1558 if (list.size() == 2) {
1559 return list.get(1);
1560 }
1561 else {
1562 return null;
1563 }
1564 }
1565
1566
1573 public List<MBMessage> filterFindByGroupId(long groupId)
1574 throws SystemException {
1575 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1576 QueryUtil.ALL_POS, null);
1577 }
1578
1579
1592 public List<MBMessage> filterFindByGroupId(long groupId, int start, int end)
1593 throws SystemException {
1594 return filterFindByGroupId(groupId, start, end, null);
1595 }
1596
1597
1611 public List<MBMessage> filterFindByGroupId(long groupId, int start,
1612 int end, OrderByComparator orderByComparator) throws SystemException {
1613 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1614 return findByGroupId(groupId, start, end, orderByComparator);
1615 }
1616
1617 StringBundler query = null;
1618
1619 if (orderByComparator != null) {
1620 query = new StringBundler(3 +
1621 (orderByComparator.getOrderByFields().length * 3));
1622 }
1623 else {
1624 query = new StringBundler(3);
1625 }
1626
1627 if (getDB().isSupportsInlineDistinct()) {
1628 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
1629 }
1630 else {
1631 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
1632 }
1633
1634 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1635
1636 if (!getDB().isSupportsInlineDistinct()) {
1637 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
1638 }
1639
1640 if (orderByComparator != null) {
1641 if (getDB().isSupportsInlineDistinct()) {
1642 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1643 orderByComparator);
1644 }
1645 else {
1646 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1647 orderByComparator);
1648 }
1649 }
1650
1651 else {
1652 if (getDB().isSupportsInlineDistinct()) {
1653 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1654 }
1655 else {
1656 query.append(MBMessageModelImpl.ORDER_BY_SQL);
1657 }
1658 }
1659
1660 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1661 MBMessage.class.getName(), _FILTER_COLUMN_PK,
1662 _FILTER_COLUMN_USERID, groupId);
1663
1664 Session session = null;
1665
1666 try {
1667 session = openSession();
1668
1669 SQLQuery q = session.createSQLQuery(sql);
1670
1671 if (getDB().isSupportsInlineDistinct()) {
1672 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
1673 }
1674 else {
1675 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
1676 }
1677
1678 QueryPos qPos = QueryPos.getInstance(q);
1679
1680 qPos.add(groupId);
1681
1682 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
1683 }
1684 catch (Exception e) {
1685 throw processException(e);
1686 }
1687 finally {
1688 closeSession(session);
1689 }
1690 }
1691
1692
1699 public List<MBMessage> findByCompanyId(long companyId)
1700 throws SystemException {
1701 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1702 null);
1703 }
1704
1705
1718 public List<MBMessage> findByCompanyId(long companyId, int start, int end)
1719 throws SystemException {
1720 return findByCompanyId(companyId, start, end, null);
1721 }
1722
1723
1737 public List<MBMessage> findByCompanyId(long companyId, int start, int end,
1738 OrderByComparator orderByComparator) throws SystemException {
1739 Object[] finderArgs = new Object[] {
1740 companyId,
1741
1742 String.valueOf(start), String.valueOf(end),
1743 String.valueOf(orderByComparator)
1744 };
1745
1746 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1747 finderArgs, this);
1748
1749 if (list == null) {
1750 StringBundler query = null;
1751
1752 if (orderByComparator != null) {
1753 query = new StringBundler(3 +
1754 (orderByComparator.getOrderByFields().length * 3));
1755 }
1756 else {
1757 query = new StringBundler(3);
1758 }
1759
1760 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1761
1762 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1763
1764 if (orderByComparator != null) {
1765 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1766 orderByComparator);
1767 }
1768
1769 else {
1770 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1771 }
1772
1773 String sql = query.toString();
1774
1775 Session session = null;
1776
1777 try {
1778 session = openSession();
1779
1780 Query q = session.createQuery(sql);
1781
1782 QueryPos qPos = QueryPos.getInstance(q);
1783
1784 qPos.add(companyId);
1785
1786 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
1787 end);
1788 }
1789 catch (Exception e) {
1790 throw processException(e);
1791 }
1792 finally {
1793 if (list == null) {
1794 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_COMPANYID,
1795 finderArgs);
1796 }
1797 else {
1798 cacheResult(list);
1799
1800 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1801 finderArgs, list);
1802 }
1803
1804 closeSession(session);
1805 }
1806 }
1807
1808 return list;
1809 }
1810
1811
1824 public MBMessage findByCompanyId_First(long companyId,
1825 OrderByComparator orderByComparator)
1826 throws NoSuchMessageException, SystemException {
1827 List<MBMessage> list = findByCompanyId(companyId, 0, 1,
1828 orderByComparator);
1829
1830 if (list.isEmpty()) {
1831 StringBundler msg = new StringBundler(4);
1832
1833 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1834
1835 msg.append("companyId=");
1836 msg.append(companyId);
1837
1838 msg.append(StringPool.CLOSE_CURLY_BRACE);
1839
1840 throw new NoSuchMessageException(msg.toString());
1841 }
1842 else {
1843 return list.get(0);
1844 }
1845 }
1846
1847
1860 public MBMessage findByCompanyId_Last(long companyId,
1861 OrderByComparator orderByComparator)
1862 throws NoSuchMessageException, SystemException {
1863 int count = countByCompanyId(companyId);
1864
1865 List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
1866 orderByComparator);
1867
1868 if (list.isEmpty()) {
1869 StringBundler msg = new StringBundler(4);
1870
1871 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1872
1873 msg.append("companyId=");
1874 msg.append(companyId);
1875
1876 msg.append(StringPool.CLOSE_CURLY_BRACE);
1877
1878 throw new NoSuchMessageException(msg.toString());
1879 }
1880 else {
1881 return list.get(0);
1882 }
1883 }
1884
1885
1899 public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
1900 long companyId, OrderByComparator orderByComparator)
1901 throws NoSuchMessageException, SystemException {
1902 MBMessage mbMessage = findByPrimaryKey(messageId);
1903
1904 Session session = null;
1905
1906 try {
1907 session = openSession();
1908
1909 MBMessage[] array = new MBMessageImpl[3];
1910
1911 array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
1912 companyId, orderByComparator, true);
1913
1914 array[1] = mbMessage;
1915
1916 array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
1917 companyId, orderByComparator, false);
1918
1919 return array;
1920 }
1921 catch (Exception e) {
1922 throw processException(e);
1923 }
1924 finally {
1925 closeSession(session);
1926 }
1927 }
1928
1929 protected MBMessage getByCompanyId_PrevAndNext(Session session,
1930 MBMessage mbMessage, long companyId,
1931 OrderByComparator orderByComparator, boolean previous) {
1932 StringBundler query = null;
1933
1934 if (orderByComparator != null) {
1935 query = new StringBundler(6 +
1936 (orderByComparator.getOrderByFields().length * 6));
1937 }
1938 else {
1939 query = new StringBundler(3);
1940 }
1941
1942 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1943
1944 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1945
1946 if (orderByComparator != null) {
1947 String[] orderByFields = orderByComparator.getOrderByFields();
1948
1949 if (orderByFields.length > 0) {
1950 query.append(WHERE_AND);
1951 }
1952
1953 for (int i = 0; i < orderByFields.length; i++) {
1954 query.append(_ORDER_BY_ENTITY_ALIAS);
1955 query.append(orderByFields[i]);
1956
1957 if ((i + 1) < orderByFields.length) {
1958 if (orderByComparator.isAscending() ^ previous) {
1959 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1960 }
1961 else {
1962 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1963 }
1964 }
1965 else {
1966 if (orderByComparator.isAscending() ^ previous) {
1967 query.append(WHERE_GREATER_THAN);
1968 }
1969 else {
1970 query.append(WHERE_LESSER_THAN);
1971 }
1972 }
1973 }
1974
1975 query.append(ORDER_BY_CLAUSE);
1976
1977 for (int i = 0; i < orderByFields.length; i++) {
1978 query.append(_ORDER_BY_ENTITY_ALIAS);
1979 query.append(orderByFields[i]);
1980
1981 if ((i + 1) < orderByFields.length) {
1982 if (orderByComparator.isAscending() ^ previous) {
1983 query.append(ORDER_BY_ASC_HAS_NEXT);
1984 }
1985 else {
1986 query.append(ORDER_BY_DESC_HAS_NEXT);
1987 }
1988 }
1989 else {
1990 if (orderByComparator.isAscending() ^ previous) {
1991 query.append(ORDER_BY_ASC);
1992 }
1993 else {
1994 query.append(ORDER_BY_DESC);
1995 }
1996 }
1997 }
1998 }
1999
2000 else {
2001 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2002 }
2003
2004 String sql = query.toString();
2005
2006 Query q = session.createQuery(sql);
2007
2008 q.setFirstResult(0);
2009 q.setMaxResults(2);
2010
2011 QueryPos qPos = QueryPos.getInstance(q);
2012
2013 qPos.add(companyId);
2014
2015 if (orderByComparator != null) {
2016 Object[] values = orderByComparator.getOrderByValues(mbMessage);
2017
2018 for (Object value : values) {
2019 qPos.add(value);
2020 }
2021 }
2022
2023 List<MBMessage> list = q.list();
2024
2025 if (list.size() == 2) {
2026 return list.get(1);
2027 }
2028 else {
2029 return null;
2030 }
2031 }
2032
2033
2040 public List<MBMessage> findByThreadId(long threadId)
2041 throws SystemException {
2042 return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2043 null);
2044 }
2045
2046
2059 public List<MBMessage> findByThreadId(long threadId, int start, int end)
2060 throws SystemException {
2061 return findByThreadId(threadId, start, end, null);
2062 }
2063
2064
2078 public List<MBMessage> findByThreadId(long threadId, int start, int end,
2079 OrderByComparator orderByComparator) throws SystemException {
2080 Object[] finderArgs = new Object[] {
2081 threadId,
2082
2083 String.valueOf(start), String.valueOf(end),
2084 String.valueOf(orderByComparator)
2085 };
2086
2087 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_THREADID,
2088 finderArgs, this);
2089
2090 if (list == null) {
2091 StringBundler query = null;
2092
2093 if (orderByComparator != null) {
2094 query = new StringBundler(3 +
2095 (orderByComparator.getOrderByFields().length * 3));
2096 }
2097 else {
2098 query = new StringBundler(3);
2099 }
2100
2101 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2102
2103 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
2104
2105 if (orderByComparator != null) {
2106 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2107 orderByComparator);
2108 }
2109
2110 else {
2111 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2112 }
2113
2114 String sql = query.toString();
2115
2116 Session session = null;
2117
2118 try {
2119 session = openSession();
2120
2121 Query q = session.createQuery(sql);
2122
2123 QueryPos qPos = QueryPos.getInstance(q);
2124
2125 qPos.add(threadId);
2126
2127 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2128 end);
2129 }
2130 catch (Exception e) {
2131 throw processException(e);
2132 }
2133 finally {
2134 if (list == null) {
2135 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_THREADID,
2136 finderArgs);
2137 }
2138 else {
2139 cacheResult(list);
2140
2141 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_THREADID,
2142 finderArgs, list);
2143 }
2144
2145 closeSession(session);
2146 }
2147 }
2148
2149 return list;
2150 }
2151
2152
2165 public MBMessage findByThreadId_First(long threadId,
2166 OrderByComparator orderByComparator)
2167 throws NoSuchMessageException, SystemException {
2168 List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
2169
2170 if (list.isEmpty()) {
2171 StringBundler msg = new StringBundler(4);
2172
2173 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2174
2175 msg.append("threadId=");
2176 msg.append(threadId);
2177
2178 msg.append(StringPool.CLOSE_CURLY_BRACE);
2179
2180 throw new NoSuchMessageException(msg.toString());
2181 }
2182 else {
2183 return list.get(0);
2184 }
2185 }
2186
2187
2200 public MBMessage findByThreadId_Last(long threadId,
2201 OrderByComparator orderByComparator)
2202 throws NoSuchMessageException, SystemException {
2203 int count = countByThreadId(threadId);
2204
2205 List<MBMessage> list = findByThreadId(threadId, count - 1, count,
2206 orderByComparator);
2207
2208 if (list.isEmpty()) {
2209 StringBundler msg = new StringBundler(4);
2210
2211 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2212
2213 msg.append("threadId=");
2214 msg.append(threadId);
2215
2216 msg.append(StringPool.CLOSE_CURLY_BRACE);
2217
2218 throw new NoSuchMessageException(msg.toString());
2219 }
2220 else {
2221 return list.get(0);
2222 }
2223 }
2224
2225
2239 public MBMessage[] findByThreadId_PrevAndNext(long messageId,
2240 long threadId, OrderByComparator orderByComparator)
2241 throws NoSuchMessageException, SystemException {
2242 MBMessage mbMessage = findByPrimaryKey(messageId);
2243
2244 Session session = null;
2245
2246 try {
2247 session = openSession();
2248
2249 MBMessage[] array = new MBMessageImpl[3];
2250
2251 array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
2252 orderByComparator, true);
2253
2254 array[1] = mbMessage;
2255
2256 array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
2257 orderByComparator, false);
2258
2259 return array;
2260 }
2261 catch (Exception e) {
2262 throw processException(e);
2263 }
2264 finally {
2265 closeSession(session);
2266 }
2267 }
2268
2269 protected MBMessage getByThreadId_PrevAndNext(Session session,
2270 MBMessage mbMessage, long threadId,
2271 OrderByComparator orderByComparator, boolean previous) {
2272 StringBundler query = null;
2273
2274 if (orderByComparator != null) {
2275 query = new StringBundler(6 +
2276 (orderByComparator.getOrderByFields().length * 6));
2277 }
2278 else {
2279 query = new StringBundler(3);
2280 }
2281
2282 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2283
2284 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
2285
2286 if (orderByComparator != null) {
2287 String[] orderByFields = orderByComparator.getOrderByFields();
2288
2289 if (orderByFields.length > 0) {
2290 query.append(WHERE_AND);
2291 }
2292
2293 for (int i = 0; i < orderByFields.length; i++) {
2294 query.append(_ORDER_BY_ENTITY_ALIAS);
2295 query.append(orderByFields[i]);
2296
2297 if ((i + 1) < orderByFields.length) {
2298 if (orderByComparator.isAscending() ^ previous) {
2299 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2300 }
2301 else {
2302 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2303 }
2304 }
2305 else {
2306 if (orderByComparator.isAscending() ^ previous) {
2307 query.append(WHERE_GREATER_THAN);
2308 }
2309 else {
2310 query.append(WHERE_LESSER_THAN);
2311 }
2312 }
2313 }
2314
2315 query.append(ORDER_BY_CLAUSE);
2316
2317 for (int i = 0; i < orderByFields.length; i++) {
2318 query.append(_ORDER_BY_ENTITY_ALIAS);
2319 query.append(orderByFields[i]);
2320
2321 if ((i + 1) < orderByFields.length) {
2322 if (orderByComparator.isAscending() ^ previous) {
2323 query.append(ORDER_BY_ASC_HAS_NEXT);
2324 }
2325 else {
2326 query.append(ORDER_BY_DESC_HAS_NEXT);
2327 }
2328 }
2329 else {
2330 if (orderByComparator.isAscending() ^ previous) {
2331 query.append(ORDER_BY_ASC);
2332 }
2333 else {
2334 query.append(ORDER_BY_DESC);
2335 }
2336 }
2337 }
2338 }
2339
2340 else {
2341 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2342 }
2343
2344 String sql = query.toString();
2345
2346 Query q = session.createQuery(sql);
2347
2348 q.setFirstResult(0);
2349 q.setMaxResults(2);
2350
2351 QueryPos qPos = QueryPos.getInstance(q);
2352
2353 qPos.add(threadId);
2354
2355 if (orderByComparator != null) {
2356 Object[] values = orderByComparator.getOrderByValues(mbMessage);
2357
2358 for (Object value : values) {
2359 qPos.add(value);
2360 }
2361 }
2362
2363 List<MBMessage> list = q.list();
2364
2365 if (list.size() == 2) {
2366 return list.get(1);
2367 }
2368 else {
2369 return null;
2370 }
2371 }
2372
2373
2380 public List<MBMessage> findByThreadReplies(long threadId)
2381 throws SystemException {
2382 return findByThreadReplies(threadId, QueryUtil.ALL_POS,
2383 QueryUtil.ALL_POS, null);
2384 }
2385
2386
2399 public List<MBMessage> findByThreadReplies(long threadId, int start, int end)
2400 throws SystemException {
2401 return findByThreadReplies(threadId, start, end, null);
2402 }
2403
2404
2418 public List<MBMessage> findByThreadReplies(long threadId, int start,
2419 int end, OrderByComparator orderByComparator) throws SystemException {
2420 Object[] finderArgs = new Object[] {
2421 threadId,
2422
2423 String.valueOf(start), String.valueOf(end),
2424 String.valueOf(orderByComparator)
2425 };
2426
2427 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_THREADREPLIES,
2428 finderArgs, this);
2429
2430 if (list == null) {
2431 StringBundler query = null;
2432
2433 if (orderByComparator != null) {
2434 query = new StringBundler(3 +
2435 (orderByComparator.getOrderByFields().length * 3));
2436 }
2437 else {
2438 query = new StringBundler(3);
2439 }
2440
2441 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2442
2443 query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
2444
2445 if (orderByComparator != null) {
2446 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2447 orderByComparator);
2448 }
2449
2450 else {
2451 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2452 }
2453
2454 String sql = query.toString();
2455
2456 Session session = null;
2457
2458 try {
2459 session = openSession();
2460
2461 Query q = session.createQuery(sql);
2462
2463 QueryPos qPos = QueryPos.getInstance(q);
2464
2465 qPos.add(threadId);
2466
2467 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2468 end);
2469 }
2470 catch (Exception e) {
2471 throw processException(e);
2472 }
2473 finally {
2474 if (list == null) {
2475 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_THREADREPLIES,
2476 finderArgs);
2477 }
2478 else {
2479 cacheResult(list);
2480
2481 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_THREADREPLIES,
2482 finderArgs, list);
2483 }
2484
2485 closeSession(session);
2486 }
2487 }
2488
2489 return list;
2490 }
2491
2492
2505 public MBMessage findByThreadReplies_First(long threadId,
2506 OrderByComparator orderByComparator)
2507 throws NoSuchMessageException, SystemException {
2508 List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
2509 orderByComparator);
2510
2511 if (list.isEmpty()) {
2512 StringBundler msg = new StringBundler(4);
2513
2514 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2515
2516 msg.append("threadId=");
2517 msg.append(threadId);
2518
2519 msg.append(StringPool.CLOSE_CURLY_BRACE);
2520
2521 throw new NoSuchMessageException(msg.toString());
2522 }
2523 else {
2524 return list.get(0);
2525 }
2526 }
2527
2528
2541 public MBMessage findByThreadReplies_Last(long threadId,
2542 OrderByComparator orderByComparator)
2543 throws NoSuchMessageException, SystemException {
2544 int count = countByThreadReplies(threadId);
2545
2546 List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
2547 orderByComparator);
2548
2549 if (list.isEmpty()) {
2550 StringBundler msg = new StringBundler(4);
2551
2552 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2553
2554 msg.append("threadId=");
2555 msg.append(threadId);
2556
2557 msg.append(StringPool.CLOSE_CURLY_BRACE);
2558
2559 throw new NoSuchMessageException(msg.toString());
2560 }
2561 else {
2562 return list.get(0);
2563 }
2564 }
2565
2566
2580 public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
2581 long threadId, OrderByComparator orderByComparator)
2582 throws NoSuchMessageException, SystemException {
2583 MBMessage mbMessage = findByPrimaryKey(messageId);
2584
2585 Session session = null;
2586
2587 try {
2588 session = openSession();
2589
2590 MBMessage[] array = new MBMessageImpl[3];
2591
2592 array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
2593 threadId, orderByComparator, true);
2594
2595 array[1] = mbMessage;
2596
2597 array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
2598 threadId, orderByComparator, false);
2599
2600 return array;
2601 }
2602 catch (Exception e) {
2603 throw processException(e);
2604 }
2605 finally {
2606 closeSession(session);
2607 }
2608 }
2609
2610 protected MBMessage getByThreadReplies_PrevAndNext(Session session,
2611 MBMessage mbMessage, long threadId,
2612 OrderByComparator orderByComparator, boolean previous) {
2613 StringBundler query = null;
2614
2615 if (orderByComparator != null) {
2616 query = new StringBundler(6 +
2617 (orderByComparator.getOrderByFields().length * 6));
2618 }
2619 else {
2620 query = new StringBundler(3);
2621 }
2622
2623 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2624
2625 query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
2626
2627 if (orderByComparator != null) {
2628 String[] orderByFields = orderByComparator.getOrderByFields();
2629
2630 if (orderByFields.length > 0) {
2631 query.append(WHERE_AND);
2632 }
2633
2634 for (int i = 0; i < orderByFields.length; i++) {
2635 query.append(_ORDER_BY_ENTITY_ALIAS);
2636 query.append(orderByFields[i]);
2637
2638 if ((i + 1) < orderByFields.length) {
2639 if (orderByComparator.isAscending() ^ previous) {
2640 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2641 }
2642 else {
2643 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2644 }
2645 }
2646 else {
2647 if (orderByComparator.isAscending() ^ previous) {
2648 query.append(WHERE_GREATER_THAN);
2649 }
2650 else {
2651 query.append(WHERE_LESSER_THAN);
2652 }
2653 }
2654 }
2655
2656 query.append(ORDER_BY_CLAUSE);
2657
2658 for (int i = 0; i < orderByFields.length; i++) {
2659 query.append(_ORDER_BY_ENTITY_ALIAS);
2660 query.append(orderByFields[i]);
2661
2662 if ((i + 1) < orderByFields.length) {
2663 if (orderByComparator.isAscending() ^ previous) {
2664 query.append(ORDER_BY_ASC_HAS_NEXT);
2665 }
2666 else {
2667 query.append(ORDER_BY_DESC_HAS_NEXT);
2668 }
2669 }
2670 else {
2671 if (orderByComparator.isAscending() ^ previous) {
2672 query.append(ORDER_BY_ASC);
2673 }
2674 else {
2675 query.append(ORDER_BY_DESC);
2676 }
2677 }
2678 }
2679 }
2680
2681 else {
2682 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2683 }
2684
2685 String sql = query.toString();
2686
2687 Query q = session.createQuery(sql);
2688
2689 q.setFirstResult(0);
2690 q.setMaxResults(2);
2691
2692 QueryPos qPos = QueryPos.getInstance(q);
2693
2694 qPos.add(threadId);
2695
2696 if (orderByComparator != null) {
2697 Object[] values = orderByComparator.getOrderByValues(mbMessage);
2698
2699 for (Object value : values) {
2700 qPos.add(value);
2701 }
2702 }
2703
2704 List<MBMessage> list = q.list();
2705
2706 if (list.size() == 2) {
2707 return list.get(1);
2708 }
2709 else {
2710 return null;
2711 }
2712 }
2713
2714
2721 public List<MBMessage> findByUserId(long userId) throws SystemException {
2722 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2723 }
2724
2725
2738 public List<MBMessage> findByUserId(long userId, int start, int end)
2739 throws SystemException {
2740 return findByUserId(userId, start, end, null);
2741 }
2742
2743
2757 public List<MBMessage> findByUserId(long userId, int start, int end,
2758 OrderByComparator orderByComparator) throws SystemException {
2759 Object[] finderArgs = new Object[] {
2760 userId,
2761
2762 String.valueOf(start), String.valueOf(end),
2763 String.valueOf(orderByComparator)
2764 };
2765
2766 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
2767 finderArgs, this);
2768
2769 if (list == null) {
2770 StringBundler query = null;
2771
2772 if (orderByComparator != null) {
2773 query = new StringBundler(3 +
2774 (orderByComparator.getOrderByFields().length * 3));
2775 }
2776 else {
2777 query = new StringBundler(3);
2778 }
2779
2780 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2781
2782 query.append(_FINDER_COLUMN_USERID_USERID_2);
2783
2784 if (orderByComparator != null) {
2785 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2786 orderByComparator);
2787 }
2788
2789 else {
2790 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2791 }
2792
2793 String sql = query.toString();
2794
2795 Session session = null;
2796
2797 try {
2798 session = openSession();
2799
2800 Query q = session.createQuery(sql);
2801
2802 QueryPos qPos = QueryPos.getInstance(q);
2803
2804 qPos.add(userId);
2805
2806 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2807 end);
2808 }
2809 catch (Exception e) {
2810 throw processException(e);
2811 }
2812 finally {
2813 if (list == null) {
2814 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_USERID,
2815 finderArgs);
2816 }
2817 else {
2818 cacheResult(list);
2819
2820 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
2821 finderArgs, list);
2822 }
2823
2824 closeSession(session);
2825 }
2826 }
2827
2828 return list;
2829 }
2830
2831
2844 public MBMessage findByUserId_First(long userId,
2845 OrderByComparator orderByComparator)
2846 throws NoSuchMessageException, SystemException {
2847 List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
2848
2849 if (list.isEmpty()) {
2850 StringBundler msg = new StringBundler(4);
2851
2852 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2853
2854 msg.append("userId=");
2855 msg.append(userId);
2856
2857 msg.append(StringPool.CLOSE_CURLY_BRACE);
2858
2859 throw new NoSuchMessageException(msg.toString());
2860 }
2861 else {
2862 return list.get(0);
2863 }
2864 }
2865
2866
2879 public MBMessage findByUserId_Last(long userId,
2880 OrderByComparator orderByComparator)
2881 throws NoSuchMessageException, SystemException {
2882 int count = countByUserId(userId);
2883
2884 List<MBMessage> list = findByUserId(userId, count - 1, count,
2885 orderByComparator);
2886
2887 if (list.isEmpty()) {
2888 StringBundler msg = new StringBundler(4);
2889
2890 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2891
2892 msg.append("userId=");
2893 msg.append(userId);
2894
2895 msg.append(StringPool.CLOSE_CURLY_BRACE);
2896
2897 throw new NoSuchMessageException(msg.toString());
2898 }
2899 else {
2900 return list.get(0);
2901 }
2902 }
2903
2904
2918 public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
2919 OrderByComparator orderByComparator)
2920 throws NoSuchMessageException, SystemException {
2921 MBMessage mbMessage = findByPrimaryKey(messageId);
2922
2923 Session session = null;
2924
2925 try {
2926 session = openSession();
2927
2928 MBMessage[] array = new MBMessageImpl[3];
2929
2930 array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
2931 orderByComparator, true);
2932
2933 array[1] = mbMessage;
2934
2935 array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
2936 orderByComparator, false);
2937
2938 return array;
2939 }
2940 catch (Exception e) {
2941 throw processException(e);
2942 }
2943 finally {
2944 closeSession(session);
2945 }
2946 }
2947
2948 protected MBMessage getByUserId_PrevAndNext(Session session,
2949 MBMessage mbMessage, long userId, OrderByComparator orderByComparator,
2950 boolean previous) {
2951 StringBundler query = null;
2952
2953 if (orderByComparator != null) {
2954 query = new StringBundler(6 +
2955 (orderByComparator.getOrderByFields().length * 6));
2956 }
2957 else {
2958 query = new StringBundler(3);
2959 }
2960
2961 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2962
2963 query.append(_FINDER_COLUMN_USERID_USERID_2);
2964
2965 if (orderByComparator != null) {
2966 String[] orderByFields = orderByComparator.getOrderByFields();
2967
2968 if (orderByFields.length > 0) {
2969 query.append(WHERE_AND);
2970 }
2971
2972 for (int i = 0; i < orderByFields.length; i++) {
2973 query.append(_ORDER_BY_ENTITY_ALIAS);
2974 query.append(orderByFields[i]);
2975
2976 if ((i + 1) < orderByFields.length) {
2977 if (orderByComparator.isAscending() ^ previous) {
2978 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2979 }
2980 else {
2981 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2982 }
2983 }
2984 else {
2985 if (orderByComparator.isAscending() ^ previous) {
2986 query.append(WHERE_GREATER_THAN);
2987 }
2988 else {
2989 query.append(WHERE_LESSER_THAN);
2990 }
2991 }
2992 }
2993
2994 query.append(ORDER_BY_CLAUSE);
2995
2996 for (int i = 0; i < orderByFields.length; i++) {
2997 query.append(_ORDER_BY_ENTITY_ALIAS);
2998 query.append(orderByFields[i]);
2999
3000 if ((i + 1) < orderByFields.length) {
3001 if (orderByComparator.isAscending() ^ previous) {
3002 query.append(ORDER_BY_ASC_HAS_NEXT);
3003 }
3004 else {
3005 query.append(ORDER_BY_DESC_HAS_NEXT);
3006 }
3007 }
3008 else {
3009 if (orderByComparator.isAscending() ^ previous) {
3010 query.append(ORDER_BY_ASC);
3011 }
3012 else {
3013 query.append(ORDER_BY_DESC);
3014 }
3015 }
3016 }
3017 }
3018
3019 else {
3020 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3021 }
3022
3023 String sql = query.toString();
3024
3025 Query q = session.createQuery(sql);
3026
3027 q.setFirstResult(0);
3028 q.setMaxResults(2);
3029
3030 QueryPos qPos = QueryPos.getInstance(q);
3031
3032 qPos.add(userId);
3033
3034 if (orderByComparator != null) {
3035 Object[] values = orderByComparator.getOrderByValues(mbMessage);
3036
3037 for (Object value : values) {
3038 qPos.add(value);
3039 }
3040 }
3041
3042 List<MBMessage> list = q.list();
3043
3044 if (list.size() == 2) {
3045 return list.get(1);
3046 }
3047 else {
3048 return null;
3049 }
3050 }
3051
3052
3060 public List<MBMessage> findByG_U(long groupId, long userId)
3061 throws SystemException {
3062 return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3063 null);
3064 }
3065
3066
3080 public List<MBMessage> findByG_U(long groupId, long userId, int start,
3081 int end) throws SystemException {
3082 return findByG_U(groupId, userId, start, end, null);
3083 }
3084
3085
3100 public List<MBMessage> findByG_U(long groupId, long userId, int start,
3101 int end, OrderByComparator orderByComparator) throws SystemException {
3102 Object[] finderArgs = new Object[] {
3103 groupId, userId,
3104
3105 String.valueOf(start), String.valueOf(end),
3106 String.valueOf(orderByComparator)
3107 };
3108
3109 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
3110 finderArgs, this);
3111
3112 if (list == null) {
3113 StringBundler query = null;
3114
3115 if (orderByComparator != null) {
3116 query = new StringBundler(4 +
3117 (orderByComparator.getOrderByFields().length * 3));
3118 }
3119 else {
3120 query = new StringBundler(4);
3121 }
3122
3123 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3124
3125 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
3126
3127 query.append(_FINDER_COLUMN_G_U_USERID_2);
3128
3129 if (orderByComparator != null) {
3130 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3131 orderByComparator);
3132 }
3133
3134 else {
3135 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3136 }
3137
3138 String sql = query.toString();
3139
3140 Session session = null;
3141
3142 try {
3143 session = openSession();
3144
3145 Query q = session.createQuery(sql);
3146
3147 QueryPos qPos = QueryPos.getInstance(q);
3148
3149 qPos.add(groupId);
3150
3151 qPos.add(userId);
3152
3153 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3154 end);
3155 }
3156 catch (Exception e) {
3157 throw processException(e);
3158 }
3159 finally {
3160 if (list == null) {
3161 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_U,
3162 finderArgs);
3163 }
3164 else {
3165 cacheResult(list);
3166
3167 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U,
3168 finderArgs, list);
3169 }
3170
3171 closeSession(session);
3172 }
3173 }
3174
3175 return list;
3176 }
3177
3178
3192 public MBMessage findByG_U_First(long groupId, long userId,
3193 OrderByComparator orderByComparator)
3194 throws NoSuchMessageException, SystemException {
3195 List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
3196 orderByComparator);
3197
3198 if (list.isEmpty()) {
3199 StringBundler msg = new StringBundler(6);
3200
3201 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3202
3203 msg.append("groupId=");
3204 msg.append(groupId);
3205
3206 msg.append(", userId=");
3207 msg.append(userId);
3208
3209 msg.append(StringPool.CLOSE_CURLY_BRACE);
3210
3211 throw new NoSuchMessageException(msg.toString());
3212 }
3213 else {
3214 return list.get(0);
3215 }
3216 }
3217
3218
3232 public MBMessage findByG_U_Last(long groupId, long userId,
3233 OrderByComparator orderByComparator)
3234 throws NoSuchMessageException, SystemException {
3235 int count = countByG_U(groupId, userId);
3236
3237 List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
3238 orderByComparator);
3239
3240 if (list.isEmpty()) {
3241 StringBundler msg = new StringBundler(6);
3242
3243 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3244
3245 msg.append("groupId=");
3246 msg.append(groupId);
3247
3248 msg.append(", userId=");
3249 msg.append(userId);
3250
3251 msg.append(StringPool.CLOSE_CURLY_BRACE);
3252
3253 throw new NoSuchMessageException(msg.toString());
3254 }
3255 else {
3256 return list.get(0);
3257 }
3258 }
3259
3260
3275 public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
3276 long userId, OrderByComparator orderByComparator)
3277 throws NoSuchMessageException, SystemException {
3278 MBMessage mbMessage = findByPrimaryKey(messageId);
3279
3280 Session session = null;
3281
3282 try {
3283 session = openSession();
3284
3285 MBMessage[] array = new MBMessageImpl[3];
3286
3287 array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
3288 userId, orderByComparator, true);
3289
3290 array[1] = mbMessage;
3291
3292 array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
3293 userId, orderByComparator, false);
3294
3295 return array;
3296 }
3297 catch (Exception e) {
3298 throw processException(e);
3299 }
3300 finally {
3301 closeSession(session);
3302 }
3303 }
3304
3305 protected MBMessage getByG_U_PrevAndNext(Session session,
3306 MBMessage mbMessage, long groupId, long userId,
3307 OrderByComparator orderByComparator, boolean previous) {
3308 StringBundler query = null;
3309
3310 if (orderByComparator != null) {
3311 query = new StringBundler(6 +
3312 (orderByComparator.getOrderByFields().length * 6));
3313 }
3314 else {
3315 query = new StringBundler(3);
3316 }
3317
3318 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3319
3320 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
3321
3322 query.append(_FINDER_COLUMN_G_U_USERID_2);
3323
3324 if (orderByComparator != null) {
3325 String[] orderByFields = orderByComparator.getOrderByFields();
3326
3327 if (orderByFields.length > 0) {
3328 query.append(WHERE_AND);
3329 }
3330
3331 for (int i = 0; i < orderByFields.length; i++) {
3332 query.append(_ORDER_BY_ENTITY_ALIAS);
3333 query.append(orderByFields[i]);
3334
3335 if ((i + 1) < orderByFields.length) {
3336 if (orderByComparator.isAscending() ^ previous) {
3337 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3338 }
3339 else {
3340 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3341 }
3342 }
3343 else {
3344 if (orderByComparator.isAscending() ^ previous) {
3345 query.append(WHERE_GREATER_THAN);
3346 }
3347 else {
3348 query.append(WHERE_LESSER_THAN);
3349 }
3350 }
3351 }
3352
3353 query.append(ORDER_BY_CLAUSE);
3354
3355 for (int i = 0; i < orderByFields.length; i++) {
3356 query.append(_ORDER_BY_ENTITY_ALIAS);
3357 query.append(orderByFields[i]);
3358
3359 if ((i + 1) < orderByFields.length) {
3360 if (orderByComparator.isAscending() ^ previous) {
3361 query.append(ORDER_BY_ASC_HAS_NEXT);
3362 }
3363 else {
3364 query.append(ORDER_BY_DESC_HAS_NEXT);
3365 }
3366 }
3367 else {
3368 if (orderByComparator.isAscending() ^ previous) {
3369 query.append(ORDER_BY_ASC);
3370 }
3371 else {
3372 query.append(ORDER_BY_DESC);
3373 }
3374 }
3375 }
3376 }
3377
3378 else {
3379 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3380 }
3381
3382 String sql = query.toString();
3383
3384 Query q = session.createQuery(sql);
3385
3386 q.setFirstResult(0);
3387 q.setMaxResults(2);
3388
3389 QueryPos qPos = QueryPos.getInstance(q);
3390
3391 qPos.add(groupId);
3392
3393 qPos.add(userId);
3394
3395 if (orderByComparator != null) {
3396 Object[] values = orderByComparator.getOrderByValues(mbMessage);
3397
3398 for (Object value : values) {
3399 qPos.add(value);
3400 }
3401 }
3402
3403 List<MBMessage> list = q.list();
3404
3405 if (list.size() == 2) {
3406 return list.get(1);
3407 }
3408 else {
3409 return null;
3410 }
3411 }
3412
3413
3421 public List<MBMessage> filterFindByG_U(long groupId, long userId)
3422 throws SystemException {
3423 return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
3424 QueryUtil.ALL_POS, null);
3425 }
3426
3427
3441 public List<MBMessage> filterFindByG_U(long groupId, long userId,
3442 int start, int end) throws SystemException {
3443 return filterFindByG_U(groupId, userId, start, end, null);
3444 }
3445
3446
3461 public List<MBMessage> filterFindByG_U(long groupId, long userId,
3462 int start, int end, OrderByComparator orderByComparator)
3463 throws SystemException {
3464 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3465 return findByG_U(groupId, userId, start, end, orderByComparator);
3466 }
3467
3468 StringBundler query = null;
3469
3470 if (orderByComparator != null) {
3471 query = new StringBundler(4 +
3472 (orderByComparator.getOrderByFields().length * 3));
3473 }
3474 else {
3475 query = new StringBundler(4);
3476 }
3477
3478 if (getDB().isSupportsInlineDistinct()) {
3479 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
3480 }
3481 else {
3482 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
3483 }
3484
3485 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
3486
3487 query.append(_FINDER_COLUMN_G_U_USERID_2);
3488
3489 if (!getDB().isSupportsInlineDistinct()) {
3490 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
3491 }
3492
3493 if (orderByComparator != null) {
3494 if (getDB().isSupportsInlineDistinct()) {
3495 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3496 orderByComparator);
3497 }
3498 else {
3499 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3500 orderByComparator);
3501 }
3502 }
3503
3504 else {
3505 if (getDB().isSupportsInlineDistinct()) {
3506 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3507 }
3508 else {
3509 query.append(MBMessageModelImpl.ORDER_BY_SQL);
3510 }
3511 }
3512
3513 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3514 MBMessage.class.getName(), _FILTER_COLUMN_PK,
3515 _FILTER_COLUMN_USERID, groupId);
3516
3517 Session session = null;
3518
3519 try {
3520 session = openSession();
3521
3522 SQLQuery q = session.createSQLQuery(sql);
3523
3524 if (getDB().isSupportsInlineDistinct()) {
3525 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
3526 }
3527 else {
3528 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
3529 }
3530
3531 QueryPos qPos = QueryPos.getInstance(q);
3532
3533 qPos.add(groupId);
3534
3535 qPos.add(userId);
3536
3537 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
3538 }
3539 catch (Exception e) {
3540 throw processException(e);
3541 }
3542 finally {
3543 closeSession(session);
3544 }
3545 }
3546
3547
3555 public List<MBMessage> findByG_C(long groupId, long categoryId)
3556 throws SystemException {
3557 return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
3558 QueryUtil.ALL_POS, null);
3559 }
3560
3561
3575 public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
3576 int end) throws SystemException {
3577 return findByG_C(groupId, categoryId, start, end, null);
3578 }
3579
3580
3595 public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
3596 int end, OrderByComparator orderByComparator) throws SystemException {
3597 Object[] finderArgs = new Object[] {
3598 groupId, categoryId,
3599
3600 String.valueOf(start), String.valueOf(end),
3601 String.valueOf(orderByComparator)
3602 };
3603
3604 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C,
3605 finderArgs, this);
3606
3607 if (list == null) {
3608 StringBundler query = null;
3609
3610 if (orderByComparator != null) {
3611 query = new StringBundler(4 +
3612 (orderByComparator.getOrderByFields().length * 3));
3613 }
3614 else {
3615 query = new StringBundler(4);
3616 }
3617
3618 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3619
3620 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3621
3622 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3623
3624 if (orderByComparator != null) {
3625 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3626 orderByComparator);
3627 }
3628
3629 else {
3630 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3631 }
3632
3633 String sql = query.toString();
3634
3635 Session session = null;
3636
3637 try {
3638 session = openSession();
3639
3640 Query q = session.createQuery(sql);
3641
3642 QueryPos qPos = QueryPos.getInstance(q);
3643
3644 qPos.add(groupId);
3645
3646 qPos.add(categoryId);
3647
3648 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3649 end);
3650 }
3651 catch (Exception e) {
3652 throw processException(e);
3653 }
3654 finally {
3655 if (list == null) {
3656 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_C,
3657 finderArgs);
3658 }
3659 else {
3660 cacheResult(list);
3661
3662 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C,
3663 finderArgs, list);
3664 }
3665
3666 closeSession(session);
3667 }
3668 }
3669
3670 return list;
3671 }
3672
3673
3687 public MBMessage findByG_C_First(long groupId, long categoryId,
3688 OrderByComparator orderByComparator)
3689 throws NoSuchMessageException, SystemException {
3690 List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
3691 orderByComparator);
3692
3693 if (list.isEmpty()) {
3694 StringBundler msg = new StringBundler(6);
3695
3696 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3697
3698 msg.append("groupId=");
3699 msg.append(groupId);
3700
3701 msg.append(", categoryId=");
3702 msg.append(categoryId);
3703
3704 msg.append(StringPool.CLOSE_CURLY_BRACE);
3705
3706 throw new NoSuchMessageException(msg.toString());
3707 }
3708 else {
3709 return list.get(0);
3710 }
3711 }
3712
3713
3727 public MBMessage findByG_C_Last(long groupId, long categoryId,
3728 OrderByComparator orderByComparator)
3729 throws NoSuchMessageException, SystemException {
3730 int count = countByG_C(groupId, categoryId);
3731
3732 List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
3733 orderByComparator);
3734
3735 if (list.isEmpty()) {
3736 StringBundler msg = new StringBundler(6);
3737
3738 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3739
3740 msg.append("groupId=");
3741 msg.append(groupId);
3742
3743 msg.append(", categoryId=");
3744 msg.append(categoryId);
3745
3746 msg.append(StringPool.CLOSE_CURLY_BRACE);
3747
3748 throw new NoSuchMessageException(msg.toString());
3749 }
3750 else {
3751 return list.get(0);
3752 }
3753 }
3754
3755
3770 public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
3771 long categoryId, OrderByComparator orderByComparator)
3772 throws NoSuchMessageException, SystemException {
3773 MBMessage mbMessage = findByPrimaryKey(messageId);
3774
3775 Session session = null;
3776
3777 try {
3778 session = openSession();
3779
3780 MBMessage[] array = new MBMessageImpl[3];
3781
3782 array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
3783 categoryId, orderByComparator, true);
3784
3785 array[1] = mbMessage;
3786
3787 array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
3788 categoryId, orderByComparator, false);
3789
3790 return array;
3791 }
3792 catch (Exception e) {
3793 throw processException(e);
3794 }
3795 finally {
3796 closeSession(session);
3797 }
3798 }
3799
3800 protected MBMessage getByG_C_PrevAndNext(Session session,
3801 MBMessage mbMessage, long groupId, long categoryId,
3802 OrderByComparator orderByComparator, boolean previous) {
3803 StringBundler query = null;
3804
3805 if (orderByComparator != null) {
3806 query = new StringBundler(6 +
3807 (orderByComparator.getOrderByFields().length * 6));
3808 }
3809 else {
3810 query = new StringBundler(3);
3811 }
3812
3813 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3814
3815 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3816
3817 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3818
3819 if (orderByComparator != null) {
3820 String[] orderByFields = orderByComparator.getOrderByFields();
3821
3822 if (orderByFields.length > 0) {
3823 query.append(WHERE_AND);
3824 }
3825
3826 for (int i = 0; i < orderByFields.length; i++) {
3827 query.append(_ORDER_BY_ENTITY_ALIAS);
3828 query.append(orderByFields[i]);
3829
3830 if ((i + 1) < orderByFields.length) {
3831 if (orderByComparator.isAscending() ^ previous) {
3832 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3833 }
3834 else {
3835 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3836 }
3837 }
3838 else {
3839 if (orderByComparator.isAscending() ^ previous) {
3840 query.append(WHERE_GREATER_THAN);
3841 }
3842 else {
3843 query.append(WHERE_LESSER_THAN);
3844 }
3845 }
3846 }
3847
3848 query.append(ORDER_BY_CLAUSE);
3849
3850 for (int i = 0; i < orderByFields.length; i++) {
3851 query.append(_ORDER_BY_ENTITY_ALIAS);
3852 query.append(orderByFields[i]);
3853
3854 if ((i + 1) < orderByFields.length) {
3855 if (orderByComparator.isAscending() ^ previous) {
3856 query.append(ORDER_BY_ASC_HAS_NEXT);
3857 }
3858 else {
3859 query.append(ORDER_BY_DESC_HAS_NEXT);
3860 }
3861 }
3862 else {
3863 if (orderByComparator.isAscending() ^ previous) {
3864 query.append(ORDER_BY_ASC);
3865 }
3866 else {
3867 query.append(ORDER_BY_DESC);
3868 }
3869 }
3870 }
3871 }
3872
3873 else {
3874 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3875 }
3876
3877 String sql = query.toString();
3878
3879 Query q = session.createQuery(sql);
3880
3881 q.setFirstResult(0);
3882 q.setMaxResults(2);
3883
3884 QueryPos qPos = QueryPos.getInstance(q);
3885
3886 qPos.add(groupId);
3887
3888 qPos.add(categoryId);
3889
3890 if (orderByComparator != null) {
3891 Object[] values = orderByComparator.getOrderByValues(mbMessage);
3892
3893 for (Object value : values) {
3894 qPos.add(value);
3895 }
3896 }
3897
3898 List<MBMessage> list = q.list();
3899
3900 if (list.size() == 2) {
3901 return list.get(1);
3902 }
3903 else {
3904 return null;
3905 }
3906 }
3907
3908
3916 public List<MBMessage> filterFindByG_C(long groupId, long categoryId)
3917 throws SystemException {
3918 return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
3919 QueryUtil.ALL_POS, null);
3920 }
3921
3922
3936 public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
3937 int start, int end) throws SystemException {
3938 return filterFindByG_C(groupId, categoryId, start, end, null);
3939 }
3940
3941
3956 public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
3957 int start, int end, OrderByComparator orderByComparator)
3958 throws SystemException {
3959 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3960 return findByG_C(groupId, categoryId, start, end, orderByComparator);
3961 }
3962
3963 StringBundler query = null;
3964
3965 if (orderByComparator != null) {
3966 query = new StringBundler(4 +
3967 (orderByComparator.getOrderByFields().length * 3));
3968 }
3969 else {
3970 query = new StringBundler(4);
3971 }
3972
3973 if (getDB().isSupportsInlineDistinct()) {
3974 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
3975 }
3976 else {
3977 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
3978 }
3979
3980 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3981
3982 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3983
3984 if (!getDB().isSupportsInlineDistinct()) {
3985 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
3986 }
3987
3988 if (orderByComparator != null) {
3989 if (getDB().isSupportsInlineDistinct()) {
3990 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3991 orderByComparator);
3992 }
3993 else {
3994 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3995 orderByComparator);
3996 }
3997 }
3998
3999 else {
4000 if (getDB().isSupportsInlineDistinct()) {
4001 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4002 }
4003 else {
4004 query.append(MBMessageModelImpl.ORDER_BY_SQL);
4005 }
4006 }
4007
4008 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4009 MBMessage.class.getName(), _FILTER_COLUMN_PK,
4010 _FILTER_COLUMN_USERID, groupId);
4011
4012 Session session = null;
4013
4014 try {
4015 session = openSession();
4016
4017 SQLQuery q = session.createSQLQuery(sql);
4018
4019 if (getDB().isSupportsInlineDistinct()) {
4020 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4021 }
4022 else {
4023 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4024 }
4025
4026 QueryPos qPos = QueryPos.getInstance(q);
4027
4028 qPos.add(groupId);
4029
4030 qPos.add(categoryId);
4031
4032 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4033 }
4034 catch (Exception e) {
4035 throw processException(e);
4036 }
4037 finally {
4038 closeSession(session);
4039 }
4040 }
4041
4042
4050 public List<MBMessage> findByG_S(long groupId, int status)
4051 throws SystemException {
4052 return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4053 null);
4054 }
4055
4056
4070 public List<MBMessage> findByG_S(long groupId, int status, int start,
4071 int end) throws SystemException {
4072 return findByG_S(groupId, status, start, end, null);
4073 }
4074
4075
4090 public List<MBMessage> findByG_S(long groupId, int status, int start,
4091 int end, OrderByComparator orderByComparator) throws SystemException {
4092 Object[] finderArgs = new Object[] {
4093 groupId, status,
4094
4095 String.valueOf(start), String.valueOf(end),
4096 String.valueOf(orderByComparator)
4097 };
4098
4099 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_S,
4100 finderArgs, this);
4101
4102 if (list == null) {
4103 StringBundler query = null;
4104
4105 if (orderByComparator != null) {
4106 query = new StringBundler(4 +
4107 (orderByComparator.getOrderByFields().length * 3));
4108 }
4109 else {
4110 query = new StringBundler(4);
4111 }
4112
4113 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4114
4115 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4116
4117 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4118
4119 if (orderByComparator != null) {
4120 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4121 orderByComparator);
4122 }
4123
4124 else {
4125 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4126 }
4127
4128 String sql = query.toString();
4129
4130 Session session = null;
4131
4132 try {
4133 session = openSession();
4134
4135 Query q = session.createQuery(sql);
4136
4137 QueryPos qPos = QueryPos.getInstance(q);
4138
4139 qPos.add(groupId);
4140
4141 qPos.add(status);
4142
4143 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
4144 end);
4145 }
4146 catch (Exception e) {
4147 throw processException(e);
4148 }
4149 finally {
4150 if (list == null) {
4151 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_S,
4152 finderArgs);
4153 }
4154 else {
4155 cacheResult(list);
4156
4157 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_S,
4158 finderArgs, list);
4159 }
4160
4161 closeSession(session);
4162 }
4163 }
4164
4165 return list;
4166 }
4167
4168
4182 public MBMessage findByG_S_First(long groupId, int status,
4183 OrderByComparator orderByComparator)
4184 throws NoSuchMessageException, SystemException {
4185 List<MBMessage> list = findByG_S(groupId, status, 0, 1,
4186 orderByComparator);
4187
4188 if (list.isEmpty()) {
4189 StringBundler msg = new StringBundler(6);
4190
4191 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4192
4193 msg.append("groupId=");
4194 msg.append(groupId);
4195
4196 msg.append(", status=");
4197 msg.append(status);
4198
4199 msg.append(StringPool.CLOSE_CURLY_BRACE);
4200
4201 throw new NoSuchMessageException(msg.toString());
4202 }
4203 else {
4204 return list.get(0);
4205 }
4206 }
4207
4208
4222 public MBMessage findByG_S_Last(long groupId, int status,
4223 OrderByComparator orderByComparator)
4224 throws NoSuchMessageException, SystemException {
4225 int count = countByG_S(groupId, status);
4226
4227 List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
4228 orderByComparator);
4229
4230 if (list.isEmpty()) {
4231 StringBundler msg = new StringBundler(6);
4232
4233 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4234
4235 msg.append("groupId=");
4236 msg.append(groupId);
4237
4238 msg.append(", status=");
4239 msg.append(status);
4240
4241 msg.append(StringPool.CLOSE_CURLY_BRACE);
4242
4243 throw new NoSuchMessageException(msg.toString());
4244 }
4245 else {
4246 return list.get(0);
4247 }
4248 }
4249
4250
4265 public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
4266 int status, OrderByComparator orderByComparator)
4267 throws NoSuchMessageException, SystemException {
4268 MBMessage mbMessage = findByPrimaryKey(messageId);
4269
4270 Session session = null;
4271
4272 try {
4273 session = openSession();
4274
4275 MBMessage[] array = new MBMessageImpl[3];
4276
4277 array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
4278 status, orderByComparator, true);
4279
4280 array[1] = mbMessage;
4281
4282 array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
4283 status, orderByComparator, false);
4284
4285 return array;
4286 }
4287 catch (Exception e) {
4288 throw processException(e);
4289 }
4290 finally {
4291 closeSession(session);
4292 }
4293 }
4294
4295 protected MBMessage getByG_S_PrevAndNext(Session session,
4296 MBMessage mbMessage, long groupId, int status,
4297 OrderByComparator orderByComparator, boolean previous) {
4298 StringBundler query = null;
4299
4300 if (orderByComparator != null) {
4301 query = new StringBundler(6 +
4302 (orderByComparator.getOrderByFields().length * 6));
4303 }
4304 else {
4305 query = new StringBundler(3);
4306 }
4307
4308 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4309
4310 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4311
4312 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4313
4314 if (orderByComparator != null) {
4315 String[] orderByFields = orderByComparator.getOrderByFields();
4316
4317 if (orderByFields.length > 0) {
4318 query.append(WHERE_AND);
4319 }
4320
4321 for (int i = 0; i < orderByFields.length; i++) {
4322 query.append(_ORDER_BY_ENTITY_ALIAS);
4323 query.append(orderByFields[i]);
4324
4325 if ((i + 1) < orderByFields.length) {
4326 if (orderByComparator.isAscending() ^ previous) {
4327 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4328 }
4329 else {
4330 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4331 }
4332 }
4333 else {
4334 if (orderByComparator.isAscending() ^ previous) {
4335 query.append(WHERE_GREATER_THAN);
4336 }
4337 else {
4338 query.append(WHERE_LESSER_THAN);
4339 }
4340 }
4341 }
4342
4343 query.append(ORDER_BY_CLAUSE);
4344
4345 for (int i = 0; i < orderByFields.length; i++) {
4346 query.append(_ORDER_BY_ENTITY_ALIAS);
4347 query.append(orderByFields[i]);
4348
4349 if ((i + 1) < orderByFields.length) {
4350 if (orderByComparator.isAscending() ^ previous) {
4351 query.append(ORDER_BY_ASC_HAS_NEXT);
4352 }
4353 else {
4354 query.append(ORDER_BY_DESC_HAS_NEXT);
4355 }
4356 }
4357 else {
4358 if (orderByComparator.isAscending() ^ previous) {
4359 query.append(ORDER_BY_ASC);
4360 }
4361 else {
4362 query.append(ORDER_BY_DESC);
4363 }
4364 }
4365 }
4366 }
4367
4368 else {
4369 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4370 }
4371
4372 String sql = query.toString();
4373
4374 Query q = session.createQuery(sql);
4375
4376 q.setFirstResult(0);
4377 q.setMaxResults(2);
4378
4379 QueryPos qPos = QueryPos.getInstance(q);
4380
4381 qPos.add(groupId);
4382
4383 qPos.add(status);
4384
4385 if (orderByComparator != null) {
4386 Object[] values = orderByComparator.getOrderByValues(mbMessage);
4387
4388 for (Object value : values) {
4389 qPos.add(value);
4390 }
4391 }
4392
4393 List<MBMessage> list = q.list();
4394
4395 if (list.size() == 2) {
4396 return list.get(1);
4397 }
4398 else {
4399 return null;
4400 }
4401 }
4402
4403
4411 public List<MBMessage> filterFindByG_S(long groupId, int status)
4412 throws SystemException {
4413 return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
4414 QueryUtil.ALL_POS, null);
4415 }
4416
4417
4431 public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
4432 int end) throws SystemException {
4433 return filterFindByG_S(groupId, status, start, end, null);
4434 }
4435
4436
4451 public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
4452 int end, OrderByComparator orderByComparator) throws SystemException {
4453 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4454 return findByG_S(groupId, status, start, end, orderByComparator);
4455 }
4456
4457 StringBundler query = null;
4458
4459 if (orderByComparator != null) {
4460 query = new StringBundler(4 +
4461 (orderByComparator.getOrderByFields().length * 3));
4462 }
4463 else {
4464 query = new StringBundler(4);
4465 }
4466
4467 if (getDB().isSupportsInlineDistinct()) {
4468 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4469 }
4470 else {
4471 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4472 }
4473
4474 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4475
4476 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4477
4478 if (!getDB().isSupportsInlineDistinct()) {
4479 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4480 }
4481
4482 if (orderByComparator != null) {
4483 if (getDB().isSupportsInlineDistinct()) {
4484 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4485 orderByComparator);
4486 }
4487 else {
4488 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4489 orderByComparator);
4490 }
4491 }
4492
4493 else {
4494 if (getDB().isSupportsInlineDistinct()) {
4495 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4496 }
4497 else {
4498 query.append(MBMessageModelImpl.ORDER_BY_SQL);
4499 }
4500 }
4501
4502 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4503 MBMessage.class.getName(), _FILTER_COLUMN_PK,
4504 _FILTER_COLUMN_USERID, groupId);
4505
4506 Session session = null;
4507
4508 try {
4509 session = openSession();
4510
4511 SQLQuery q = session.createSQLQuery(sql);
4512
4513 if (getDB().isSupportsInlineDistinct()) {
4514 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4515 }
4516 else {
4517 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4518 }
4519
4520 QueryPos qPos = QueryPos.getInstance(q);
4521
4522 qPos.add(groupId);
4523
4524 qPos.add(status);
4525
4526 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4527 }
4528 catch (Exception e) {
4529 throw processException(e);
4530 }
4531 finally {
4532 closeSession(session);
4533 }
4534 }
4535
4536
4544 public List<MBMessage> findByC_S(long companyId, int status)
4545 throws SystemException {
4546 return findByC_S(companyId, status, QueryUtil.ALL_POS,
4547 QueryUtil.ALL_POS, null);
4548 }
4549
4550
4564 public List<MBMessage> findByC_S(long companyId, int status, int start,
4565 int end) throws SystemException {
4566 return findByC_S(companyId, status, start, end, null);
4567 }
4568
4569
4584 public List<MBMessage> findByC_S(long companyId, int status, int start,
4585 int end, OrderByComparator orderByComparator) throws SystemException {
4586 Object[] finderArgs = new Object[] {
4587 companyId, status,
4588
4589 String.valueOf(start), String.valueOf(end),
4590 String.valueOf(orderByComparator)
4591 };
4592
4593 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_S,
4594 finderArgs, this);
4595
4596 if (list == null) {
4597 StringBundler query = null;
4598
4599 if (orderByComparator != null) {
4600 query = new StringBundler(4 +
4601 (orderByComparator.getOrderByFields().length * 3));
4602 }
4603 else {
4604 query = new StringBundler(4);
4605 }
4606
4607 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4608
4609 query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
4610
4611 query.append(_FINDER_COLUMN_C_S_STATUS_2);
4612
4613 if (orderByComparator != null) {
4614 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4615 orderByComparator);
4616 }
4617
4618 else {
4619 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4620 }
4621
4622 String sql = query.toString();
4623
4624 Session session = null;
4625
4626 try {
4627 session = openSession();
4628
4629 Query q = session.createQuery(sql);
4630
4631 QueryPos qPos = QueryPos.getInstance(q);
4632
4633 qPos.add(companyId);
4634
4635 qPos.add(status);
4636
4637 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
4638 end);
4639 }
4640 catch (Exception e) {
4641 throw processException(e);
4642 }
4643 finally {
4644 if (list == null) {
4645 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_C_S,
4646 finderArgs);
4647 }
4648 else {
4649 cacheResult(list);
4650
4651 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_S,
4652 finderArgs, list);
4653 }
4654
4655 closeSession(session);
4656 }
4657 }
4658
4659 return list;
4660 }
4661
4662
4676 public MBMessage findByC_S_First(long companyId, int status,
4677 OrderByComparator orderByComparator)
4678 throws NoSuchMessageException, SystemException {
4679 List<MBMessage> list = findByC_S(companyId, status, 0, 1,
4680 orderByComparator);
4681
4682 if (list.isEmpty()) {
4683 StringBundler msg = new StringBundler(6);
4684
4685 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4686
4687 msg.append("companyId=");
4688 msg.append(companyId);
4689
4690 msg.append(", status=");
4691 msg.append(status);
4692
4693 msg.append(StringPool.CLOSE_CURLY_BRACE);
4694
4695 throw new NoSuchMessageException(msg.toString());
4696 }
4697 else {
4698 return list.get(0);
4699 }
4700 }
4701
4702
4716 public MBMessage findByC_S_Last(long companyId, int status,
4717 OrderByComparator orderByComparator)
4718 throws NoSuchMessageException, SystemException {
4719 int count = countByC_S(companyId, status);
4720
4721 List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
4722 orderByComparator);
4723
4724 if (list.isEmpty()) {
4725 StringBundler msg = new StringBundler(6);
4726
4727 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4728
4729 msg.append("companyId=");
4730 msg.append(companyId);
4731
4732 msg.append(", status=");
4733 msg.append(status);
4734
4735 msg.append(StringPool.CLOSE_CURLY_BRACE);
4736
4737 throw new NoSuchMessageException(msg.toString());
4738 }
4739 else {
4740 return list.get(0);
4741 }
4742 }
4743
4744
4759 public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
4760 int status, OrderByComparator orderByComparator)
4761 throws NoSuchMessageException, SystemException {
4762 MBMessage mbMessage = findByPrimaryKey(messageId);
4763
4764 Session session = null;
4765
4766 try {
4767 session = openSession();
4768
4769 MBMessage[] array = new MBMessageImpl[3];
4770
4771 array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
4772 status, orderByComparator, true);
4773
4774 array[1] = mbMessage;
4775
4776 array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
4777 status, orderByComparator, false);
4778
4779 return array;
4780 }
4781 catch (Exception e) {
4782 throw processException(e);
4783 }
4784 finally {
4785 closeSession(session);
4786 }
4787 }
4788
4789 protected MBMessage getByC_S_PrevAndNext(Session session,
4790 MBMessage mbMessage, long companyId, int status,
4791 OrderByComparator orderByComparator, boolean previous) {
4792 StringBundler query = null;
4793
4794 if (orderByComparator != null) {
4795 query = new StringBundler(6 +
4796 (orderByComparator.getOrderByFields().length * 6));
4797 }
4798 else {
4799 query = new StringBundler(3);
4800 }
4801
4802 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4803
4804 query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
4805
4806 query.append(_FINDER_COLUMN_C_S_STATUS_2);
4807
4808 if (orderByComparator != null) {
4809 String[] orderByFields = orderByComparator.getOrderByFields();
4810
4811 if (orderByFields.length > 0) {
4812 query.append(WHERE_AND);
4813 }
4814
4815 for (int i = 0; i < orderByFields.length; i++) {
4816 query.append(_ORDER_BY_ENTITY_ALIAS);
4817 query.append(orderByFields[i]);
4818
4819 if ((i + 1) < orderByFields.length) {
4820 if (orderByComparator.isAscending() ^ previous) {
4821 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4822 }
4823 else {
4824 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4825 }
4826 }
4827 else {
4828 if (orderByComparator.isAscending() ^ previous) {
4829 query.append(WHERE_GREATER_THAN);
4830 }
4831 else {
4832 query.append(WHERE_LESSER_THAN);
4833 }
4834 }
4835 }
4836
4837 query.append(ORDER_BY_CLAUSE);
4838
4839 for (int i = 0; i < orderByFields.length; i++) {
4840 query.append(_ORDER_BY_ENTITY_ALIAS);
4841 query.append(orderByFields[i]);
4842
4843 if ((i + 1) < orderByFields.length) {
4844 if (orderByComparator.isAscending() ^ previous) {
4845 query.append(ORDER_BY_ASC_HAS_NEXT);
4846 }
4847 else {
4848 query.append(ORDER_BY_DESC_HAS_NEXT);
4849 }
4850 }
4851 else {
4852 if (orderByComparator.isAscending() ^ previous) {
4853 query.append(ORDER_BY_ASC);
4854 }
4855 else {
4856 query.append(ORDER_BY_DESC);
4857 }
4858 }
4859 }
4860 }
4861
4862 else {
4863 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4864 }
4865
4866 String sql = query.toString();
4867
4868 Query q = session.createQuery(sql);
4869
4870 q.setFirstResult(0);
4871 q.setMaxResults(2);
4872
4873 QueryPos qPos = QueryPos.getInstance(q);
4874
4875 qPos.add(companyId);
4876
4877 qPos.add(status);
4878
4879 if (orderByComparator != null) {
4880 Object[] values = orderByComparator.getOrderByValues(mbMessage);
4881
4882 for (Object value : values) {
4883 qPos.add(value);
4884 }
4885 }
4886
4887 List<MBMessage> list = q.list();
4888
4889 if (list.size() == 2) {
4890 return list.get(1);
4891 }
4892 else {
4893 return null;
4894 }
4895 }
4896
4897
4905 public List<MBMessage> findByC_C(long classNameId, long classPK)
4906 throws SystemException {
4907 return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
4908 QueryUtil.ALL_POS, null);
4909 }
4910
4911
4925 public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
4926 int end) throws SystemException {
4927 return findByC_C(classNameId, classPK, start, end, null);
4928 }
4929
4930
4945 public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
4946 int end, OrderByComparator orderByComparator) throws SystemException {
4947 Object[] finderArgs = new Object[] {
4948 classNameId, classPK,
4949
4950 String.valueOf(start), String.valueOf(end),
4951 String.valueOf(orderByComparator)
4952 };
4953
4954 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
4955 finderArgs, this);
4956
4957 if (list == null) {
4958 StringBundler query = null;
4959
4960 if (orderByComparator != null) {
4961 query = new StringBundler(4 +
4962 (orderByComparator.getOrderByFields().length * 3));
4963 }
4964 else {
4965 query = new StringBundler(4);
4966 }
4967
4968 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4969
4970 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
4971
4972 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
4973
4974 if (orderByComparator != null) {
4975 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4976 orderByComparator);
4977 }
4978
4979 else {
4980 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4981 }
4982
4983 String sql = query.toString();
4984
4985 Session session = null;
4986
4987 try {
4988 session = openSession();
4989
4990 Query q = session.createQuery(sql);
4991
4992 QueryPos qPos = QueryPos.getInstance(q);
4993
4994 qPos.add(classNameId);
4995
4996 qPos.add(classPK);
4997
4998 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
4999 end);
5000 }
5001 catch (Exception e) {
5002 throw processException(e);
5003 }
5004 finally {
5005 if (list == null) {
5006 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_C_C,
5007 finderArgs);
5008 }
5009 else {
5010 cacheResult(list);
5011
5012 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C,
5013 finderArgs, list);
5014 }
5015
5016 closeSession(session);
5017 }
5018 }
5019
5020 return list;
5021 }
5022
5023
5037 public MBMessage findByC_C_First(long classNameId, long classPK,
5038 OrderByComparator orderByComparator)
5039 throws NoSuchMessageException, SystemException {
5040 List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
5041 orderByComparator);
5042
5043 if (list.isEmpty()) {
5044 StringBundler msg = new StringBundler(6);
5045
5046 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5047
5048 msg.append("classNameId=");
5049 msg.append(classNameId);
5050
5051 msg.append(", classPK=");
5052 msg.append(classPK);
5053
5054 msg.append(StringPool.CLOSE_CURLY_BRACE);
5055
5056 throw new NoSuchMessageException(msg.toString());
5057 }
5058 else {
5059 return list.get(0);
5060 }
5061 }
5062
5063
5077 public MBMessage findByC_C_Last(long classNameId, long classPK,
5078 OrderByComparator orderByComparator)
5079 throws NoSuchMessageException, SystemException {
5080 int count = countByC_C(classNameId, classPK);
5081
5082 List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
5083 count, orderByComparator);
5084
5085 if (list.isEmpty()) {
5086 StringBundler msg = new StringBundler(6);
5087
5088 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5089
5090 msg.append("classNameId=");
5091 msg.append(classNameId);
5092
5093 msg.append(", classPK=");
5094 msg.append(classPK);
5095
5096 msg.append(StringPool.CLOSE_CURLY_BRACE);
5097
5098 throw new NoSuchMessageException(msg.toString());
5099 }
5100 else {
5101 return list.get(0);
5102 }
5103 }
5104
5105
5120 public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
5121 long classPK, OrderByComparator orderByComparator)
5122 throws NoSuchMessageException, SystemException {
5123 MBMessage mbMessage = findByPrimaryKey(messageId);
5124
5125 Session session = null;
5126
5127 try {
5128 session = openSession();
5129
5130 MBMessage[] array = new MBMessageImpl[3];
5131
5132 array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
5133 classPK, orderByComparator, true);
5134
5135 array[1] = mbMessage;
5136
5137 array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
5138 classPK, orderByComparator, false);
5139
5140 return array;
5141 }
5142 catch (Exception e) {
5143 throw processException(e);
5144 }
5145 finally {
5146 closeSession(session);
5147 }
5148 }
5149
5150 protected MBMessage getByC_C_PrevAndNext(Session session,
5151 MBMessage mbMessage, long classNameId, long classPK,
5152 OrderByComparator orderByComparator, boolean previous) {
5153 StringBundler query = null;
5154
5155 if (orderByComparator != null) {
5156 query = new StringBundler(6 +
5157 (orderByComparator.getOrderByFields().length * 6));
5158 }
5159 else {
5160 query = new StringBundler(3);
5161 }
5162
5163 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5164
5165 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
5166
5167 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
5168
5169 if (orderByComparator != null) {
5170 String[] orderByFields = orderByComparator.getOrderByFields();
5171
5172 if (orderByFields.length > 0) {
5173 query.append(WHERE_AND);
5174 }
5175
5176 for (int i = 0; i < orderByFields.length; i++) {
5177 query.append(_ORDER_BY_ENTITY_ALIAS);
5178 query.append(orderByFields[i]);
5179
5180 if ((i + 1) < orderByFields.length) {
5181 if (orderByComparator.isAscending() ^ previous) {
5182 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5183 }
5184 else {
5185 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5186 }
5187 }
5188 else {
5189 if (orderByComparator.isAscending() ^ previous) {
5190 query.append(WHERE_GREATER_THAN);
5191 }
5192 else {
5193 query.append(WHERE_LESSER_THAN);
5194 }
5195 }
5196 }
5197
5198 query.append(ORDER_BY_CLAUSE);
5199
5200 for (int i = 0; i < orderByFields.length; i++) {
5201 query.append(_ORDER_BY_ENTITY_ALIAS);
5202 query.append(orderByFields[i]);
5203
5204 if ((i + 1) < orderByFields.length) {
5205 if (orderByComparator.isAscending() ^ previous) {
5206 query.append(ORDER_BY_ASC_HAS_NEXT);
5207 }
5208 else {
5209 query.append(ORDER_BY_DESC_HAS_NEXT);
5210 }
5211 }
5212 else {
5213 if (orderByComparator.isAscending() ^ previous) {
5214 query.append(ORDER_BY_ASC);
5215 }
5216 else {
5217 query.append(ORDER_BY_DESC);
5218 }
5219 }
5220 }
5221 }
5222
5223 else {
5224 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5225 }
5226
5227 String sql = query.toString();
5228
5229 Query q = session.createQuery(sql);
5230
5231 q.setFirstResult(0);
5232 q.setMaxResults(2);
5233
5234 QueryPos qPos = QueryPos.getInstance(q);
5235
5236 qPos.add(classNameId);
5237
5238 qPos.add(classPK);
5239
5240 if (orderByComparator != null) {
5241 Object[] values = orderByComparator.getOrderByValues(mbMessage);
5242
5243 for (Object value : values) {
5244 qPos.add(value);
5245 }
5246 }
5247
5248 List<MBMessage> list = q.list();
5249
5250 if (list.size() == 2) {
5251 return list.get(1);
5252 }
5253 else {
5254 return null;
5255 }
5256 }
5257
5258
5266 public List<MBMessage> findByT_P(long threadId, long parentMessageId)
5267 throws SystemException {
5268 return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
5269 QueryUtil.ALL_POS, null);
5270 }
5271
5272
5286 public List<MBMessage> findByT_P(long threadId, long parentMessageId,
5287 int start, int end) throws SystemException {
5288 return findByT_P(threadId, parentMessageId, start, end, null);
5289 }
5290
5291
5306 public List<MBMessage> findByT_P(long threadId, long parentMessageId,
5307 int start, int end, OrderByComparator orderByComparator)
5308 throws SystemException {
5309 Object[] finderArgs = new Object[] {
5310 threadId, parentMessageId,
5311
5312 String.valueOf(start), String.valueOf(end),
5313 String.valueOf(orderByComparator)
5314 };
5315
5316 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_P,
5317 finderArgs, this);
5318
5319 if (list == null) {
5320 StringBundler query = null;
5321
5322 if (orderByComparator != null) {
5323 query = new StringBundler(4 +
5324 (orderByComparator.getOrderByFields().length * 3));
5325 }
5326 else {
5327 query = new StringBundler(4);
5328 }
5329
5330 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5331
5332 query.append(_FINDER_COLUMN_T_P_THREADID_2);
5333
5334 query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
5335
5336 if (orderByComparator != null) {
5337 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5338 orderByComparator);
5339 }
5340
5341 else {
5342 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5343 }
5344
5345 String sql = query.toString();
5346
5347 Session session = null;
5348
5349 try {
5350 session = openSession();
5351
5352 Query q = session.createQuery(sql);
5353
5354 QueryPos qPos = QueryPos.getInstance(q);
5355
5356 qPos.add(threadId);
5357
5358 qPos.add(parentMessageId);
5359
5360 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
5361 end);
5362 }
5363 catch (Exception e) {
5364 throw processException(e);
5365 }
5366 finally {
5367 if (list == null) {
5368 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_T_P,
5369 finderArgs);
5370 }
5371 else {
5372 cacheResult(list);
5373
5374 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_P,
5375 finderArgs, list);
5376 }
5377
5378 closeSession(session);
5379 }
5380 }
5381
5382 return list;
5383 }
5384
5385
5399 public MBMessage findByT_P_First(long threadId, long parentMessageId,
5400 OrderByComparator orderByComparator)
5401 throws NoSuchMessageException, SystemException {
5402 List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
5403 orderByComparator);
5404
5405 if (list.isEmpty()) {
5406 StringBundler msg = new StringBundler(6);
5407
5408 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5409
5410 msg.append("threadId=");
5411 msg.append(threadId);
5412
5413 msg.append(", parentMessageId=");
5414 msg.append(parentMessageId);
5415
5416 msg.append(StringPool.CLOSE_CURLY_BRACE);
5417
5418 throw new NoSuchMessageException(msg.toString());
5419 }
5420 else {
5421 return list.get(0);
5422 }
5423 }
5424
5425
5439 public MBMessage findByT_P_Last(long threadId, long parentMessageId,
5440 OrderByComparator orderByComparator)
5441 throws NoSuchMessageException, SystemException {
5442 int count = countByT_P(threadId, parentMessageId);
5443
5444 List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
5445 count, orderByComparator);
5446
5447 if (list.isEmpty()) {
5448 StringBundler msg = new StringBundler(6);
5449
5450 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5451
5452 msg.append("threadId=");
5453 msg.append(threadId);
5454
5455 msg.append(", parentMessageId=");
5456 msg.append(parentMessageId);
5457
5458 msg.append(StringPool.CLOSE_CURLY_BRACE);
5459
5460 throw new NoSuchMessageException(msg.toString());
5461 }
5462 else {
5463 return list.get(0);
5464 }
5465 }
5466
5467
5482 public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
5483 long parentMessageId, OrderByComparator orderByComparator)
5484 throws NoSuchMessageException, SystemException {
5485 MBMessage mbMessage = findByPrimaryKey(messageId);
5486
5487 Session session = null;
5488
5489 try {
5490 session = openSession();
5491
5492 MBMessage[] array = new MBMessageImpl[3];
5493
5494 array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
5495 parentMessageId, orderByComparator, true);
5496
5497 array[1] = mbMessage;
5498
5499 array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
5500 parentMessageId, orderByComparator, false);
5501
5502 return array;
5503 }
5504 catch (Exception e) {
5505 throw processException(e);
5506 }
5507 finally {
5508 closeSession(session);
5509 }
5510 }
5511
5512 protected MBMessage getByT_P_PrevAndNext(Session session,
5513 MBMessage mbMessage, long threadId, long parentMessageId,
5514 OrderByComparator orderByComparator, boolean previous) {
5515 StringBundler query = null;
5516
5517 if (orderByComparator != null) {
5518 query = new StringBundler(6 +
5519 (orderByComparator.getOrderByFields().length * 6));
5520 }
5521 else {
5522 query = new StringBundler(3);
5523 }
5524
5525 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5526
5527 query.append(_FINDER_COLUMN_T_P_THREADID_2);
5528
5529 query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
5530
5531 if (orderByComparator != null) {
5532 String[] orderByFields = orderByComparator.getOrderByFields();
5533
5534 if (orderByFields.length > 0) {
5535 query.append(WHERE_AND);
5536 }
5537
5538 for (int i = 0; i < orderByFields.length; i++) {
5539 query.append(_ORDER_BY_ENTITY_ALIAS);
5540 query.append(orderByFields[i]);
5541
5542 if ((i + 1) < orderByFields.length) {
5543 if (orderByComparator.isAscending() ^ previous) {
5544 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5545 }
5546 else {
5547 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5548 }
5549 }
5550 else {
5551 if (orderByComparator.isAscending() ^ previous) {
5552 query.append(WHERE_GREATER_THAN);
5553 }
5554 else {
5555 query.append(WHERE_LESSER_THAN);
5556 }
5557 }
5558 }
5559
5560 query.append(ORDER_BY_CLAUSE);
5561
5562 for (int i = 0; i < orderByFields.length; i++) {
5563 query.append(_ORDER_BY_ENTITY_ALIAS);
5564 query.append(orderByFields[i]);
5565
5566 if ((i + 1) < orderByFields.length) {
5567 if (orderByComparator.isAscending() ^ previous) {
5568 query.append(ORDER_BY_ASC_HAS_NEXT);
5569 }
5570 else {
5571 query.append(ORDER_BY_DESC_HAS_NEXT);
5572 }
5573 }
5574 else {
5575 if (orderByComparator.isAscending() ^ previous) {
5576 query.append(ORDER_BY_ASC);
5577 }
5578 else {
5579 query.append(ORDER_BY_DESC);
5580 }
5581 }
5582 }
5583 }
5584
5585 else {
5586 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5587 }
5588
5589 String sql = query.toString();
5590
5591 Query q = session.createQuery(sql);
5592
5593 q.setFirstResult(0);
5594 q.setMaxResults(2);
5595
5596 QueryPos qPos = QueryPos.getInstance(q);
5597
5598 qPos.add(threadId);
5599
5600 qPos.add(parentMessageId);
5601
5602 if (orderByComparator != null) {
5603 Object[] values = orderByComparator.getOrderByValues(mbMessage);
5604
5605 for (Object value : values) {
5606 qPos.add(value);
5607 }
5608 }
5609
5610 List<MBMessage> list = q.list();
5611
5612 if (list.size() == 2) {
5613 return list.get(1);
5614 }
5615 else {
5616 return null;
5617 }
5618 }
5619
5620
5628 public List<MBMessage> findByT_S(long threadId, int status)
5629 throws SystemException {
5630 return findByT_S(threadId, status, QueryUtil.ALL_POS,
5631 QueryUtil.ALL_POS, null);
5632 }
5633
5634
5648 public List<MBMessage> findByT_S(long threadId, int status, int start,
5649 int end) throws SystemException {
5650 return findByT_S(threadId, status, start, end, null);
5651 }
5652
5653
5668 public List<MBMessage> findByT_S(long threadId, int status, int start,
5669 int end, OrderByComparator orderByComparator) throws SystemException {
5670 Object[] finderArgs = new Object[] {
5671 threadId, status,
5672
5673 String.valueOf(start), String.valueOf(end),
5674 String.valueOf(orderByComparator)
5675 };
5676
5677 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_S,
5678 finderArgs, this);
5679
5680 if (list == null) {
5681 StringBundler query = null;
5682
5683 if (orderByComparator != null) {
5684 query = new StringBundler(4 +
5685 (orderByComparator.getOrderByFields().length * 3));
5686 }
5687 else {
5688 query = new StringBundler(4);
5689 }
5690
5691 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5692
5693 query.append(_FINDER_COLUMN_T_S_THREADID_2);
5694
5695 query.append(_FINDER_COLUMN_T_S_STATUS_2);
5696
5697 if (orderByComparator != null) {
5698 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5699 orderByComparator);
5700 }
5701
5702 else {
5703 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5704 }
5705
5706 String sql = query.toString();
5707
5708 Session session = null;
5709
5710 try {
5711 session = openSession();
5712
5713 Query q = session.createQuery(sql);
5714
5715 QueryPos qPos = QueryPos.getInstance(q);
5716
5717 qPos.add(threadId);
5718
5719 qPos.add(status);
5720
5721 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
5722 end);
5723 }
5724 catch (Exception e) {
5725 throw processException(e);
5726 }
5727 finally {
5728 if (list == null) {
5729 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_T_S,
5730 finderArgs);
5731 }
5732 else {
5733 cacheResult(list);
5734
5735 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_S,
5736 finderArgs, list);
5737 }
5738
5739 closeSession(session);
5740 }
5741 }
5742
5743 return list;
5744 }
5745
5746
5760 public MBMessage findByT_S_First(long threadId, int status,
5761 OrderByComparator orderByComparator)
5762 throws NoSuchMessageException, SystemException {
5763 List<MBMessage> list = findByT_S(threadId, status, 0, 1,
5764 orderByComparator);
5765
5766 if (list.isEmpty()) {
5767 StringBundler msg = new StringBundler(6);
5768
5769 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5770
5771 msg.append("threadId=");
5772 msg.append(threadId);
5773
5774 msg.append(", status=");
5775 msg.append(status);
5776
5777 msg.append(StringPool.CLOSE_CURLY_BRACE);
5778
5779 throw new NoSuchMessageException(msg.toString());
5780 }
5781 else {
5782 return list.get(0);
5783 }
5784 }
5785
5786
5800 public MBMessage findByT_S_Last(long threadId, int status,
5801 OrderByComparator orderByComparator)
5802 throws NoSuchMessageException, SystemException {
5803 int count = countByT_S(threadId, status);
5804
5805 List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
5806 orderByComparator);
5807
5808 if (list.isEmpty()) {
5809 StringBundler msg = new StringBundler(6);
5810
5811 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5812
5813 msg.append("threadId=");
5814 msg.append(threadId);
5815
5816 msg.append(", status=");
5817 msg.append(status);
5818
5819 msg.append(StringPool.CLOSE_CURLY_BRACE);
5820
5821 throw new NoSuchMessageException(msg.toString());
5822 }
5823 else {
5824 return list.get(0);
5825 }
5826 }
5827
5828
5843 public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
5844 int status, OrderByComparator orderByComparator)
5845 throws NoSuchMessageException, SystemException {
5846 MBMessage mbMessage = findByPrimaryKey(messageId);
5847
5848 Session session = null;
5849
5850 try {
5851 session = openSession();
5852
5853 MBMessage[] array = new MBMessageImpl[3];
5854
5855 array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
5856 status, orderByComparator, true);
5857
5858 array[1] = mbMessage;
5859
5860 array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
5861 status, orderByComparator, false);
5862
5863 return array;
5864 }
5865 catch (Exception e) {
5866 throw processException(e);
5867 }
5868 finally {
5869 closeSession(session);
5870 }
5871 }
5872
5873 protected MBMessage getByT_S_PrevAndNext(Session session,
5874 MBMessage mbMessage, long threadId, int status,
5875 OrderByComparator orderByComparator, boolean previous) {
5876 StringBundler query = null;
5877
5878 if (orderByComparator != null) {
5879 query = new StringBundler(6 +
5880 (orderByComparator.getOrderByFields().length * 6));
5881 }
5882 else {
5883 query = new StringBundler(3);
5884 }
5885
5886 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5887
5888 query.append(_FINDER_COLUMN_T_S_THREADID_2);
5889
5890 query.append(_FINDER_COLUMN_T_S_STATUS_2);
5891
5892 if (orderByComparator != null) {
5893 String[] orderByFields = orderByComparator.getOrderByFields();
5894
5895 if (orderByFields.length > 0) {
5896 query.append(WHERE_AND);
5897 }
5898
5899 for (int i = 0; i < orderByFields.length; i++) {
5900 query.append(_ORDER_BY_ENTITY_ALIAS);
5901 query.append(orderByFields[i]);
5902
5903 if ((i + 1) < orderByFields.length) {
5904 if (orderByComparator.isAscending() ^ previous) {
5905 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5906 }
5907 else {
5908 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5909 }
5910 }
5911 else {
5912 if (orderByComparator.isAscending() ^ previous) {
5913 query.append(WHERE_GREATER_THAN);
5914 }
5915 else {
5916 query.append(WHERE_LESSER_THAN);
5917 }
5918 }
5919 }
5920
5921 query.append(ORDER_BY_CLAUSE);
5922
5923 for (int i = 0; i < orderByFields.length; i++) {
5924 query.append(_ORDER_BY_ENTITY_ALIAS);
5925 query.append(orderByFields[i]);
5926
5927 if ((i + 1) < orderByFields.length) {
5928 if (orderByComparator.isAscending() ^ previous) {
5929 query.append(ORDER_BY_ASC_HAS_NEXT);
5930 }
5931 else {
5932 query.append(ORDER_BY_DESC_HAS_NEXT);
5933 }
5934 }
5935 else {
5936 if (orderByComparator.isAscending() ^ previous) {
5937 query.append(ORDER_BY_ASC);
5938 }
5939 else {
5940 query.append(ORDER_BY_DESC);
5941 }
5942 }
5943 }
5944 }
5945
5946 else {
5947 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5948 }
5949
5950 String sql = query.toString();
5951
5952 Query q = session.createQuery(sql);
5953
5954 q.setFirstResult(0);
5955 q.setMaxResults(2);
5956
5957 QueryPos qPos = QueryPos.getInstance(q);
5958
5959 qPos.add(threadId);
5960
5961 qPos.add(status);
5962
5963 if (orderByComparator != null) {
5964 Object[] values = orderByComparator.getOrderByValues(mbMessage);
5965
5966 for (Object value : values) {
5967 qPos.add(value);
5968 }
5969 }
5970
5971 List<MBMessage> list = q.list();
5972
5973 if (list.size() == 2) {
5974 return list.get(1);
5975 }
5976 else {
5977 return null;
5978 }
5979 }
5980
5981
5989 public List<MBMessage> findByTR_S(long threadId, int status)
5990 throws SystemException {
5991 return findByTR_S(threadId, status, QueryUtil.ALL_POS,
5992 QueryUtil.ALL_POS, null);
5993 }
5994
5995
6009 public List<MBMessage> findByTR_S(long threadId, int status, int start,
6010 int end) throws SystemException {
6011 return findByTR_S(threadId, status, start, end, null);
6012 }
6013
6014
6029 public List<MBMessage> findByTR_S(long threadId, int status, int start,
6030 int end, OrderByComparator orderByComparator) throws SystemException {
6031 Object[] finderArgs = new Object[] {
6032 threadId, status,
6033
6034 String.valueOf(start), String.valueOf(end),
6035 String.valueOf(orderByComparator)
6036 };
6037
6038 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TR_S,
6039 finderArgs, this);
6040
6041 if (list == null) {
6042 StringBundler query = null;
6043
6044 if (orderByComparator != null) {
6045 query = new StringBundler(4 +
6046 (orderByComparator.getOrderByFields().length * 3));
6047 }
6048 else {
6049 query = new StringBundler(4);
6050 }
6051
6052 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6053
6054 query.append(_FINDER_COLUMN_TR_S_THREADID_2);
6055
6056 query.append(_FINDER_COLUMN_TR_S_STATUS_2);
6057
6058 if (orderByComparator != null) {
6059 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6060 orderByComparator);
6061 }
6062
6063 else {
6064 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6065 }
6066
6067 String sql = query.toString();
6068
6069 Session session = null;
6070
6071 try {
6072 session = openSession();
6073
6074 Query q = session.createQuery(sql);
6075
6076 QueryPos qPos = QueryPos.getInstance(q);
6077
6078 qPos.add(threadId);
6079
6080 qPos.add(status);
6081
6082 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
6083 end);
6084 }
6085 catch (Exception e) {
6086 throw processException(e);
6087 }
6088 finally {
6089 if (list == null) {
6090 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_TR_S,
6091 finderArgs);
6092 }
6093 else {
6094 cacheResult(list);
6095
6096 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TR_S,
6097 finderArgs, list);
6098 }
6099
6100 closeSession(session);
6101 }
6102 }
6103
6104 return list;
6105 }
6106
6107
6121 public MBMessage findByTR_S_First(long threadId, int status,
6122 OrderByComparator orderByComparator)
6123 throws NoSuchMessageException, SystemException {
6124 List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
6125 orderByComparator);
6126
6127 if (list.isEmpty()) {
6128 StringBundler msg = new StringBundler(6);
6129
6130 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6131
6132 msg.append("threadId=");
6133 msg.append(threadId);
6134
6135 msg.append(", status=");
6136 msg.append(status);
6137
6138 msg.append(StringPool.CLOSE_CURLY_BRACE);
6139
6140 throw new NoSuchMessageException(msg.toString());
6141 }
6142 else {
6143 return list.get(0);
6144 }
6145 }
6146
6147
6161 public MBMessage findByTR_S_Last(long threadId, int status,
6162 OrderByComparator orderByComparator)
6163 throws NoSuchMessageException, SystemException {
6164 int count = countByTR_S(threadId, status);
6165
6166 List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
6167 orderByComparator);
6168
6169 if (list.isEmpty()) {
6170 StringBundler msg = new StringBundler(6);
6171
6172 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6173
6174 msg.append("threadId=");
6175 msg.append(threadId);
6176
6177 msg.append(", status=");
6178 msg.append(status);
6179
6180 msg.append(StringPool.CLOSE_CURLY_BRACE);
6181
6182 throw new NoSuchMessageException(msg.toString());
6183 }
6184 else {
6185 return list.get(0);
6186 }
6187 }
6188
6189
6204 public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
6205 int status, OrderByComparator orderByComparator)
6206 throws NoSuchMessageException, SystemException {
6207 MBMessage mbMessage = findByPrimaryKey(messageId);
6208
6209 Session session = null;
6210
6211 try {
6212 session = openSession();
6213
6214 MBMessage[] array = new MBMessageImpl[3];
6215
6216 array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
6217 status, orderByComparator, true);
6218
6219 array[1] = mbMessage;
6220
6221 array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
6222 status, orderByComparator, false);
6223
6224 return array;
6225 }
6226 catch (Exception e) {
6227 throw processException(e);
6228 }
6229 finally {
6230 closeSession(session);
6231 }
6232 }
6233
6234 protected MBMessage getByTR_S_PrevAndNext(Session session,
6235 MBMessage mbMessage, long threadId, int status,
6236 OrderByComparator orderByComparator, boolean previous) {
6237 StringBundler query = null;
6238
6239 if (orderByComparator != null) {
6240 query = new StringBundler(6 +
6241 (orderByComparator.getOrderByFields().length * 6));
6242 }
6243 else {
6244 query = new StringBundler(3);
6245 }
6246
6247 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6248
6249 query.append(_FINDER_COLUMN_TR_S_THREADID_2);
6250
6251 query.append(_FINDER_COLUMN_TR_S_STATUS_2);
6252
6253 if (orderByComparator != null) {
6254 String[] orderByFields = orderByComparator.getOrderByFields();
6255
6256 if (orderByFields.length > 0) {
6257 query.append(WHERE_AND);
6258 }
6259
6260 for (int i = 0; i < orderByFields.length; i++) {
6261 query.append(_ORDER_BY_ENTITY_ALIAS);
6262 query.append(orderByFields[i]);
6263
6264 if ((i + 1) < orderByFields.length) {
6265 if (orderByComparator.isAscending() ^ previous) {
6266 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6267 }
6268 else {
6269 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6270 }
6271 }
6272 else {
6273 if (orderByComparator.isAscending() ^ previous) {
6274 query.append(WHERE_GREATER_THAN);
6275 }
6276 else {
6277 query.append(WHERE_LESSER_THAN);
6278 }
6279 }
6280 }
6281
6282 query.append(ORDER_BY_CLAUSE);
6283
6284 for (int i = 0; i < orderByFields.length; i++) {
6285 query.append(_ORDER_BY_ENTITY_ALIAS);
6286 query.append(orderByFields[i]);
6287
6288 if ((i + 1) < orderByFields.length) {
6289 if (orderByComparator.isAscending() ^ previous) {
6290 query.append(ORDER_BY_ASC_HAS_NEXT);
6291 }
6292 else {
6293 query.append(ORDER_BY_DESC_HAS_NEXT);
6294 }
6295 }
6296 else {
6297 if (orderByComparator.isAscending() ^ previous) {
6298 query.append(ORDER_BY_ASC);
6299 }
6300 else {
6301 query.append(ORDER_BY_DESC);
6302 }
6303 }
6304 }
6305 }
6306
6307 else {
6308 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6309 }
6310
6311 String sql = query.toString();
6312
6313 Query q = session.createQuery(sql);
6314
6315 q.setFirstResult(0);
6316 q.setMaxResults(2);
6317
6318 QueryPos qPos = QueryPos.getInstance(q);
6319
6320 qPos.add(threadId);
6321
6322 qPos.add(status);
6323
6324 if (orderByComparator != null) {
6325 Object[] values = orderByComparator.getOrderByValues(mbMessage);
6326
6327 for (Object value : values) {
6328 qPos.add(value);
6329 }
6330 }
6331
6332 List<MBMessage> list = q.list();
6333
6334 if (list.size() == 2) {
6335 return list.get(1);
6336 }
6337 else {
6338 return null;
6339 }
6340 }
6341
6342
6351 public List<MBMessage> findByG_U_S(long groupId, long userId, int status)
6352 throws SystemException {
6353 return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
6354 QueryUtil.ALL_POS, null);
6355 }
6356
6357
6372 public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
6373 int start, int end) throws SystemException {
6374 return findByG_U_S(groupId, userId, status, start, end, null);
6375 }
6376
6377
6393 public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
6394 int start, int end, OrderByComparator orderByComparator)
6395 throws SystemException {
6396 Object[] finderArgs = new Object[] {
6397 groupId, userId, status,
6398
6399 String.valueOf(start), String.valueOf(end),
6400 String.valueOf(orderByComparator)
6401 };
6402
6403 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U_S,
6404 finderArgs, this);
6405
6406 if (list == null) {
6407 StringBundler query = null;
6408
6409 if (orderByComparator != null) {
6410 query = new StringBundler(5 +
6411 (orderByComparator.getOrderByFields().length * 3));
6412 }
6413 else {
6414 query = new StringBundler(5);
6415 }
6416
6417 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6418
6419 query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
6420
6421 query.append(_FINDER_COLUMN_G_U_S_USERID_2);
6422
6423 query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
6424
6425 if (orderByComparator != null) {
6426 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6427 orderByComparator);
6428 }
6429
6430 else {
6431 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6432 }
6433
6434 String sql = query.toString();
6435
6436 Session session = null;
6437
6438 try {
6439 session = openSession();
6440
6441 Query q = session.createQuery(sql);
6442
6443 QueryPos qPos = QueryPos.getInstance(q);
6444
6445 qPos.add(groupId);
6446
6447 qPos.add(userId);
6448
6449 qPos.add(status);
6450
6451 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
6452 end);
6453 }
6454 catch (Exception e) {
6455 throw processException(e);
6456 }
6457 finally {
6458 if (list == null) {
6459 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_U_S,
6460 finderArgs);
6461 }
6462 else {
6463 cacheResult(list);
6464
6465 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U_S,
6466 finderArgs, list);
6467 }
6468
6469 closeSession(session);
6470 }
6471 }
6472
6473 return list;
6474 }
6475
6476
6491 public MBMessage findByG_U_S_First(long groupId, long userId, int status,
6492 OrderByComparator orderByComparator)
6493 throws NoSuchMessageException, SystemException {
6494 List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
6495 orderByComparator);
6496
6497 if (list.isEmpty()) {
6498 StringBundler msg = new StringBundler(8);
6499
6500 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6501
6502 msg.append("groupId=");
6503 msg.append(groupId);
6504
6505 msg.append(", userId=");
6506 msg.append(userId);
6507
6508 msg.append(", status=");
6509 msg.append(status);
6510
6511 msg.append(StringPool.CLOSE_CURLY_BRACE);
6512
6513 throw new NoSuchMessageException(msg.toString());
6514 }
6515 else {
6516 return list.get(0);
6517 }
6518 }
6519
6520
6535 public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
6536 OrderByComparator orderByComparator)
6537 throws NoSuchMessageException, SystemException {
6538 int count = countByG_U_S(groupId, userId, status);
6539
6540 List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
6541 count, orderByComparator);
6542
6543 if (list.isEmpty()) {
6544 StringBundler msg = new StringBundler(8);
6545
6546 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6547
6548 msg.append("groupId=");
6549 msg.append(groupId);
6550
6551 msg.append(", userId=");
6552 msg.append(userId);
6553
6554 msg.append(", status=");
6555 msg.append(status);
6556
6557 msg.append(StringPool.CLOSE_CURLY_BRACE);
6558
6559 throw new NoSuchMessageException(msg.toString());
6560 }
6561 else {
6562 return list.get(0);
6563 }
6564 }
6565
6566
6582 public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
6583 long userId, int status, OrderByComparator orderByComparator)
6584 throws NoSuchMessageException, SystemException {
6585 MBMessage mbMessage = findByPrimaryKey(messageId);
6586
6587 Session session = null;
6588
6589 try {
6590 session = openSession();
6591
6592 MBMessage[] array = new MBMessageImpl[3];
6593
6594 array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
6595 userId, status, orderByComparator, true);
6596
6597 array[1] = mbMessage;
6598
6599 array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
6600 userId, status, orderByComparator, false);
6601
6602 return array;
6603 }
6604 catch (Exception e) {
6605 throw processException(e);
6606 }
6607 finally {
6608 closeSession(session);
6609 }
6610 }
6611
6612 protected MBMessage getByG_U_S_PrevAndNext(Session session,
6613 MBMessage mbMessage, long groupId, long userId, int status,
6614 OrderByComparator orderByComparator, boolean previous) {
6615 StringBundler query = null;
6616
6617 if (orderByComparator != null) {
6618 query = new StringBundler(6 +
6619 (orderByComparator.getOrderByFields().length * 6));
6620 }
6621 else {
6622 query = new StringBundler(3);
6623 }
6624
6625 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6626
6627 query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
6628
6629 query.append(_FINDER_COLUMN_G_U_S_USERID_2);
6630
6631 query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
6632
6633 if (orderByComparator != null) {
6634 String[] orderByFields = orderByComparator.getOrderByFields();
6635
6636 if (orderByFields.length > 0) {
6637 query.append(WHERE_AND);
6638 }
6639
6640 for (int i = 0; i < orderByFields.length; i++) {
6641 query.append(_ORDER_BY_ENTITY_ALIAS);
6642 query.append(orderByFields[i]);
6643
6644 if ((i + 1) < orderByFields.length) {
6645 if (orderByComparator.isAscending() ^ previous) {
6646 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6647 }
6648 else {
6649 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6650 }
6651 }
6652 else {
6653 if (orderByComparator.isAscending() ^ previous) {
6654 query.append(WHERE_GREATER_THAN);
6655 }
6656 else {
6657 query.append(WHERE_LESSER_THAN);
6658 }
6659 }
6660 }
6661
6662 query.append(ORDER_BY_CLAUSE);
6663
6664 for (int i = 0; i < orderByFields.length; i++) {
6665 query.append(_ORDER_BY_ENTITY_ALIAS);
6666 query.append(orderByFields[i]);
6667
6668 if ((i + 1) < orderByFields.length) {
6669 if (orderByComparator.isAscending() ^ previous) {
6670 query.append(ORDER_BY_ASC_HAS_NEXT);
6671 }
6672 else {
6673 query.append(ORDER_BY_DESC_HAS_NEXT);
6674 }
6675 }
6676 else {
6677 if (orderByComparator.isAscending() ^ previous) {
6678 query.append(ORDER_BY_ASC);
6679 }
6680 else {
6681 query.append(ORDER_BY_DESC);
6682 }
6683 }
6684 }
6685 }
6686
6687 else {
6688 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6689 }
6690
6691 String sql = query.toString();
6692
6693 Query q = session.createQuery(sql);
6694
6695 q.setFirstResult(0);
6696 q.setMaxResults(2);
6697
6698 QueryPos qPos = QueryPos.getInstance(q);
6699
6700 qPos.add(groupId);
6701
6702 qPos.add(userId);
6703
6704 qPos.add(status);
6705
6706 if (orderByComparator != null) {
6707 Object[] values = orderByComparator.getOrderByValues(mbMessage);
6708
6709 for (Object value : values) {
6710 qPos.add(value);
6711 }
6712 }
6713
6714 List<MBMessage> list = q.list();
6715
6716 if (list.size() == 2) {
6717 return list.get(1);
6718 }
6719 else {
6720 return null;
6721 }
6722 }
6723
6724
6733 public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
6734 int status) throws SystemException {
6735 return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
6736 QueryUtil.ALL_POS, null);
6737 }
6738
6739
6754 public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
6755 int status, int start, int end) throws SystemException {
6756 return filterFindByG_U_S(groupId, userId, status, start, end, null);
6757 }
6758
6759
6775 public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
6776 int status, int start, int end, OrderByComparator orderByComparator)
6777 throws SystemException {
6778 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6779 return findByG_U_S(groupId, userId, status, start, end,
6780 orderByComparator);
6781 }
6782
6783 StringBundler query = null;
6784
6785 if (orderByComparator != null) {
6786 query = new StringBundler(5 +
6787 (orderByComparator.getOrderByFields().length * 3));
6788 }
6789 else {
6790 query = new StringBundler(5);
6791 }
6792
6793 if (getDB().isSupportsInlineDistinct()) {
6794 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6795 }
6796 else {
6797 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6798 }
6799
6800 query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
6801
6802 query.append(_FINDER_COLUMN_G_U_S_USERID_2);
6803
6804 query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
6805
6806 if (!getDB().isSupportsInlineDistinct()) {
6807 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6808 }
6809
6810 if (orderByComparator != null) {
6811 if (getDB().isSupportsInlineDistinct()) {
6812 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6813 orderByComparator);
6814 }
6815 else {
6816 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6817 orderByComparator);
6818 }
6819 }
6820
6821 else {
6822 if (getDB().isSupportsInlineDistinct()) {
6823 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6824 }
6825 else {
6826 query.append(MBMessageModelImpl.ORDER_BY_SQL);
6827 }
6828 }
6829
6830 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6831 MBMessage.class.getName(), _FILTER_COLUMN_PK,
6832 _FILTER_COLUMN_USERID, groupId);
6833
6834 Session session = null;
6835
6836 try {
6837 session = openSession();
6838
6839 SQLQuery q = session.createSQLQuery(sql);
6840
6841 if (getDB().isSupportsInlineDistinct()) {
6842 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6843 }
6844 else {
6845 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6846 }
6847
6848 QueryPos qPos = QueryPos.getInstance(q);
6849
6850 qPos.add(groupId);
6851
6852 qPos.add(userId);
6853
6854 qPos.add(status);
6855
6856 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6857 }
6858 catch (Exception e) {
6859 throw processException(e);
6860 }
6861 finally {
6862 closeSession(session);
6863 }
6864 }
6865
6866
6875 public List<MBMessage> findByG_C_T(long groupId, long categoryId,
6876 long threadId) throws SystemException {
6877 return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
6878 QueryUtil.ALL_POS, null);
6879 }
6880
6881
6896 public List<MBMessage> findByG_C_T(long groupId, long categoryId,
6897 long threadId, int start, int end) throws SystemException {
6898 return findByG_C_T(groupId, categoryId, threadId, start, end, null);
6899 }
6900
6901
6917 public List<MBMessage> findByG_C_T(long groupId, long categoryId,
6918 long threadId, int start, int end, OrderByComparator orderByComparator)
6919 throws SystemException {
6920 Object[] finderArgs = new Object[] {
6921 groupId, categoryId, threadId,
6922
6923 String.valueOf(start), String.valueOf(end),
6924 String.valueOf(orderByComparator)
6925 };
6926
6927 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C_T,
6928 finderArgs, this);
6929
6930 if (list == null) {
6931 StringBundler query = null;
6932
6933 if (orderByComparator != null) {
6934 query = new StringBundler(5 +
6935 (orderByComparator.getOrderByFields().length * 3));
6936 }
6937 else {
6938 query = new StringBundler(5);
6939 }
6940
6941 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6942
6943 query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
6944
6945 query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
6946
6947 query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
6948
6949 if (orderByComparator != null) {
6950 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6951 orderByComparator);
6952 }
6953
6954 else {
6955 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6956 }
6957
6958 String sql = query.toString();
6959
6960 Session session = null;
6961
6962 try {
6963 session = openSession();
6964
6965 Query q = session.createQuery(sql);
6966
6967 QueryPos qPos = QueryPos.getInstance(q);
6968
6969 qPos.add(groupId);
6970
6971 qPos.add(categoryId);
6972
6973 qPos.add(threadId);
6974
6975 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
6976 end);
6977 }
6978 catch (Exception e) {
6979 throw processException(e);
6980 }
6981 finally {
6982 if (list == null) {
6983 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_C_T,
6984 finderArgs);
6985 }
6986 else {
6987 cacheResult(list);
6988
6989 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C_T,
6990 finderArgs, list);
6991 }
6992
6993 closeSession(session);
6994 }
6995 }
6996
6997 return list;
6998 }
6999
7000
7015 public MBMessage findByG_C_T_First(long groupId, long categoryId,
7016 long threadId, OrderByComparator orderByComparator)
7017 throws NoSuchMessageException, SystemException {
7018 List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
7019 orderByComparator);
7020
7021 if (list.isEmpty()) {
7022 StringBundler msg = new StringBundler(8);
7023
7024 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7025
7026 msg.append("groupId=");
7027 msg.append(groupId);
7028
7029 msg.append(", categoryId=");
7030 msg.append(categoryId);
7031
7032 msg.append(", threadId=");
7033 msg.append(threadId);
7034
7035 msg.append(StringPool.CLOSE_CURLY_BRACE);
7036
7037 throw new NoSuchMessageException(msg.toString());
7038 }
7039 else {
7040 return list.get(0);
7041 }
7042 }
7043
7044
7059 public MBMessage findByG_C_T_Last(long groupId, long categoryId,
7060 long threadId, OrderByComparator orderByComparator)
7061 throws NoSuchMessageException, SystemException {
7062 int count = countByG_C_T(groupId, categoryId, threadId);
7063
7064 List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
7065 count - 1, count, orderByComparator);
7066
7067 if (list.isEmpty()) {
7068 StringBundler msg = new StringBundler(8);
7069
7070 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7071
7072 msg.append("groupId=");
7073 msg.append(groupId);
7074
7075 msg.append(", categoryId=");
7076 msg.append(categoryId);
7077
7078 msg.append(", threadId=");
7079 msg.append(threadId);
7080
7081 msg.append(StringPool.CLOSE_CURLY_BRACE);
7082
7083 throw new NoSuchMessageException(msg.toString());
7084 }
7085 else {
7086 return list.get(0);
7087 }
7088 }
7089
7090
7106 public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
7107 long categoryId, long threadId, OrderByComparator orderByComparator)
7108 throws NoSuchMessageException, SystemException {
7109 MBMessage mbMessage = findByPrimaryKey(messageId);
7110
7111 Session session = null;
7112
7113 try {
7114 session = openSession();
7115
7116 MBMessage[] array = new MBMessageImpl[3];
7117
7118 array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
7119 categoryId, threadId, orderByComparator, true);
7120
7121 array[1] = mbMessage;
7122
7123 array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
7124 categoryId, threadId, orderByComparator, false);
7125
7126 return array;
7127 }
7128 catch (Exception e) {
7129 throw processException(e);
7130 }
7131 finally {
7132 closeSession(session);
7133 }
7134 }
7135
7136 protected MBMessage getByG_C_T_PrevAndNext(Session session,
7137 MBMessage mbMessage, long groupId, long categoryId, long threadId,
7138 OrderByComparator orderByComparator, boolean previous) {
7139 StringBundler query = null;
7140
7141 if (orderByComparator != null) {
7142 query = new StringBundler(6 +
7143 (orderByComparator.getOrderByFields().length * 6));
7144 }
7145 else {
7146 query = new StringBundler(3);
7147 }
7148
7149 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7150
7151 query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
7152
7153 query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
7154
7155 query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
7156
7157 if (orderByComparator != null) {
7158 String[] orderByFields = orderByComparator.getOrderByFields();
7159
7160 if (orderByFields.length > 0) {
7161 query.append(WHERE_AND);
7162 }
7163
7164 for (int i = 0; i < orderByFields.length; i++) {
7165 query.append(_ORDER_BY_ENTITY_ALIAS);
7166 query.append(orderByFields[i]);
7167
7168 if ((i + 1) < orderByFields.length) {
7169 if (orderByComparator.isAscending() ^ previous) {
7170 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7171 }
7172 else {
7173 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7174 }
7175 }
7176 else {
7177 if (orderByComparator.isAscending() ^ previous) {
7178 query.append(WHERE_GREATER_THAN);
7179 }
7180 else {
7181 query.append(WHERE_LESSER_THAN);
7182 }
7183 }
7184 }
7185
7186 query.append(ORDER_BY_CLAUSE);
7187
7188 for (int i = 0; i < orderByFields.length; i++) {
7189 query.append(_ORDER_BY_ENTITY_ALIAS);
7190 query.append(orderByFields[i]);
7191
7192 if ((i + 1) < orderByFields.length) {
7193 if (orderByComparator.isAscending() ^ previous) {
7194 query.append(ORDER_BY_ASC_HAS_NEXT);
7195 }
7196 else {
7197 query.append(ORDER_BY_DESC_HAS_NEXT);
7198 }
7199 }
7200 else {
7201 if (orderByComparator.isAscending() ^ previous) {
7202 query.append(ORDER_BY_ASC);
7203 }
7204 else {
7205 query.append(ORDER_BY_DESC);
7206 }
7207 }
7208 }
7209 }
7210
7211 else {
7212 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7213 }
7214
7215 String sql = query.toString();
7216
7217 Query q = session.createQuery(sql);
7218
7219 q.setFirstResult(0);
7220 q.setMaxResults(2);
7221
7222 QueryPos qPos = QueryPos.getInstance(q);
7223
7224 qPos.add(groupId);
7225
7226 qPos.add(categoryId);
7227
7228 qPos.add(threadId);
7229
7230 if (orderByComparator != null) {
7231 Object[] values = orderByComparator.getOrderByValues(mbMessage);
7232
7233 for (Object value : values) {
7234 qPos.add(value);
7235 }
7236 }
7237
7238 List<MBMessage> list = q.list();
7239
7240 if (list.size() == 2) {
7241 return list.get(1);
7242 }
7243 else {
7244 return null;
7245 }
7246 }
7247
7248
7257 public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
7258 long threadId) throws SystemException {
7259 return filterFindByG_C_T(groupId, categoryId, threadId,
7260 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7261 }
7262
7263
7278 public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
7279 long threadId, int start, int end) throws SystemException {
7280 return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
7281 }
7282
7283
7299 public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
7300 long threadId, int start, int end, OrderByComparator orderByComparator)
7301 throws SystemException {
7302 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7303 return findByG_C_T(groupId, categoryId, threadId, start, end,
7304 orderByComparator);
7305 }
7306
7307 StringBundler query = null;
7308
7309 if (orderByComparator != null) {
7310 query = new StringBundler(5 +
7311 (orderByComparator.getOrderByFields().length * 3));
7312 }
7313 else {
7314 query = new StringBundler(5);
7315 }
7316
7317 if (getDB().isSupportsInlineDistinct()) {
7318 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
7319 }
7320 else {
7321 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
7322 }
7323
7324 query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
7325
7326 query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
7327
7328 query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
7329
7330 if (!getDB().isSupportsInlineDistinct()) {
7331 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
7332 }
7333
7334 if (orderByComparator != null) {
7335 if (getDB().isSupportsInlineDistinct()) {
7336 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7337 orderByComparator);
7338 }
7339 else {
7340 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7341 orderByComparator);
7342 }
7343 }
7344
7345 else {
7346 if (getDB().isSupportsInlineDistinct()) {
7347 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7348 }
7349 else {
7350 query.append(MBMessageModelImpl.ORDER_BY_SQL);
7351 }
7352 }
7353
7354 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7355 MBMessage.class.getName(), _FILTER_COLUMN_PK,
7356 _FILTER_COLUMN_USERID, groupId);
7357
7358 Session session = null;
7359
7360 try {
7361 session = openSession();
7362
7363 SQLQuery q = session.createSQLQuery(sql);
7364
7365 if (getDB().isSupportsInlineDistinct()) {
7366 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
7367 }
7368 else {
7369 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
7370 }
7371
7372 QueryPos qPos = QueryPos.getInstance(q);
7373
7374 qPos.add(groupId);
7375
7376 qPos.add(categoryId);
7377
7378 qPos.add(threadId);
7379
7380 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
7381 }
7382 catch (Exception e) {
7383 throw processException(e);
7384 }
7385 finally {
7386 closeSession(session);
7387 }
7388 }
7389
7390
7399 public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status)
7400 throws SystemException {
7401 return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
7402 QueryUtil.ALL_POS, null);
7403 }
7404
7405
7420 public List<MBMessage> findByG_C_S(long groupId, long categoryId,
7421 int status, int start, int end) throws SystemException {
7422 return findByG_C_S(groupId, categoryId, status, start, end, null);
7423 }
7424
7425
7441 public List<MBMessage> findByG_C_S(long groupId, long categoryId,
7442 int status, int start, int end, OrderByComparator orderByComparator)
7443 throws SystemException {
7444 Object[] finderArgs = new Object[] {
7445 groupId, categoryId, status,
7446
7447 String.valueOf(start), String.valueOf(end),
7448 String.valueOf(orderByComparator)
7449 };
7450
7451 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C_S,
7452 finderArgs, this);
7453
7454 if (list == null) {
7455 StringBundler query = null;
7456
7457 if (orderByComparator != null) {
7458 query = new StringBundler(5 +
7459 (orderByComparator.getOrderByFields().length * 3));
7460 }
7461 else {
7462 query = new StringBundler(5);
7463 }
7464
7465 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7466
7467 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
7468
7469 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
7470
7471 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
7472
7473 if (orderByComparator != null) {
7474 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7475 orderByComparator);
7476 }
7477
7478 else {
7479 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7480 }
7481
7482 String sql = query.toString();
7483
7484 Session session = null;
7485
7486 try {
7487 session = openSession();
7488
7489 Query q = session.createQuery(sql);
7490
7491 QueryPos qPos = QueryPos.getInstance(q);
7492
7493 qPos.add(groupId);
7494
7495 qPos.add(categoryId);
7496
7497 qPos.add(status);
7498
7499 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
7500 end);
7501 }
7502 catch (Exception e) {
7503 throw processException(e);
7504 }
7505 finally {
7506 if (list == null) {
7507 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_C_S,
7508 finderArgs);
7509 }
7510 else {
7511 cacheResult(list);
7512
7513 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C_S,
7514 finderArgs, list);
7515 }
7516
7517 closeSession(session);
7518 }
7519 }
7520
7521 return list;
7522 }
7523
7524
7539 public MBMessage findByG_C_S_First(long groupId, long categoryId,
7540 int status, OrderByComparator orderByComparator)
7541 throws NoSuchMessageException, SystemException {
7542 List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
7543 orderByComparator);
7544
7545 if (list.isEmpty()) {
7546 StringBundler msg = new StringBundler(8);
7547
7548 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7549
7550 msg.append("groupId=");
7551 msg.append(groupId);
7552
7553 msg.append(", categoryId=");
7554 msg.append(categoryId);
7555
7556 msg.append(", status=");
7557 msg.append(status);
7558
7559 msg.append(StringPool.CLOSE_CURLY_BRACE);
7560
7561 throw new NoSuchMessageException(msg.toString());
7562 }
7563 else {
7564 return list.get(0);
7565 }
7566 }
7567
7568
7583 public MBMessage findByG_C_S_Last(long groupId, long categoryId,
7584 int status, OrderByComparator orderByComparator)
7585 throws NoSuchMessageException, SystemException {
7586 int count = countByG_C_S(groupId, categoryId, status);
7587
7588 List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
7589 count - 1, count, orderByComparator);
7590
7591 if (list.isEmpty()) {
7592 StringBundler msg = new StringBundler(8);
7593
7594 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7595
7596 msg.append("groupId=");
7597 msg.append(groupId);
7598
7599 msg.append(", categoryId=");
7600 msg.append(categoryId);
7601
7602 msg.append(", status=");
7603 msg.append(status);
7604
7605 msg.append(StringPool.CLOSE_CURLY_BRACE);
7606
7607 throw new NoSuchMessageException(msg.toString());
7608 }
7609 else {
7610 return list.get(0);
7611 }
7612 }
7613
7614
7630 public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
7631 long categoryId, int status, OrderByComparator orderByComparator)
7632 throws NoSuchMessageException, SystemException {
7633 MBMessage mbMessage = findByPrimaryKey(messageId);
7634
7635 Session session = null;
7636
7637 try {
7638 session = openSession();
7639
7640 MBMessage[] array = new MBMessageImpl[3];
7641
7642 array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
7643 categoryId, status, orderByComparator, true);
7644
7645 array[1] = mbMessage;
7646
7647 array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
7648 categoryId, status, orderByComparator, false);
7649
7650 return array;
7651 }
7652 catch (Exception e) {
7653 throw processException(e);
7654 }
7655 finally {
7656 closeSession(session);
7657 }
7658 }
7659
7660 protected MBMessage getByG_C_S_PrevAndNext(Session session,
7661 MBMessage mbMessage, long groupId, long categoryId, int status,
7662 OrderByComparator orderByComparator, boolean previous) {
7663 StringBundler query = null;
7664
7665 if (orderByComparator != null) {
7666 query = new StringBundler(6 +
7667 (orderByComparator.getOrderByFields().length * 6));
7668 }
7669 else {
7670 query = new StringBundler(3);
7671 }
7672
7673 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7674
7675 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
7676
7677 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
7678
7679 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
7680
7681 if (orderByComparator != null) {
7682 String[] orderByFields = orderByComparator.getOrderByFields();
7683
7684 if (orderByFields.length > 0) {
7685 query.append(WHERE_AND);
7686 }
7687
7688 for (int i = 0; i < orderByFields.length; i++) {
7689 query.append(_ORDER_BY_ENTITY_ALIAS);
7690 query.append(orderByFields[i]);
7691
7692 if ((i + 1) < orderByFields.length) {
7693 if (orderByComparator.isAscending() ^ previous) {
7694 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7695 }
7696 else {
7697 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7698 }
7699 }
7700 else {
7701 if (orderByComparator.isAscending() ^ previous) {
7702 query.append(WHERE_GREATER_THAN);
7703 }
7704 else {
7705 query.append(WHERE_LESSER_THAN);
7706 }
7707 }
7708 }
7709
7710 query.append(ORDER_BY_CLAUSE);
7711
7712 for (int i = 0; i < orderByFields.length; i++) {
7713 query.append(_ORDER_BY_ENTITY_ALIAS);
7714 query.append(orderByFields[i]);
7715
7716 if ((i + 1) < orderByFields.length) {
7717 if (orderByComparator.isAscending() ^ previous) {
7718 query.append(ORDER_BY_ASC_HAS_NEXT);
7719 }
7720 else {
7721 query.append(ORDER_BY_DESC_HAS_NEXT);
7722 }
7723 }
7724 else {
7725 if (orderByComparator.isAscending() ^ previous) {
7726 query.append(ORDER_BY_ASC);
7727 }
7728 else {
7729 query.append(ORDER_BY_DESC);
7730 }
7731 }
7732 }
7733 }
7734
7735 else {
7736 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7737 }
7738
7739 String sql = query.toString();
7740
7741 Query q = session.createQuery(sql);
7742
7743 q.setFirstResult(0);
7744 q.setMaxResults(2);
7745
7746 QueryPos qPos = QueryPos.getInstance(q);
7747
7748 qPos.add(groupId);
7749
7750 qPos.add(categoryId);
7751
7752 qPos.add(status);
7753
7754 if (orderByComparator != null) {
7755 Object[] values = orderByComparator.getOrderByValues(mbMessage);
7756
7757 for (Object value : values) {
7758 qPos.add(value);
7759 }
7760 }
7761
7762 List<MBMessage> list = q.list();
7763
7764 if (list.size() == 2) {
7765 return list.get(1);
7766 }
7767 else {
7768 return null;
7769 }
7770 }
7771
7772
7781 public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
7782 int status) throws SystemException {
7783 return filterFindByG_C_S(groupId, categoryId, status,
7784 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7785 }
7786
7787
7802 public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
7803 int status, int start, int end) throws SystemException {
7804 return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
7805 }
7806
7807
7823 public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
7824 int status, int start, int end, OrderByComparator orderByComparator)
7825 throws SystemException {
7826 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7827 return findByG_C_S(groupId, categoryId, status, start, end,
7828 orderByComparator);
7829 }
7830
7831 StringBundler query = null;
7832
7833 if (orderByComparator != null) {
7834 query = new StringBundler(5 +
7835 (orderByComparator.getOrderByFields().length * 3));
7836 }
7837 else {
7838 query = new StringBundler(5);
7839 }
7840
7841 if (getDB().isSupportsInlineDistinct()) {
7842 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
7843 }
7844 else {
7845 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
7846 }
7847
7848 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
7849
7850 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
7851
7852 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
7853
7854 if (!getDB().isSupportsInlineDistinct()) {
7855 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
7856 }
7857
7858 if (orderByComparator != null) {
7859 if (getDB().isSupportsInlineDistinct()) {
7860 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7861 orderByComparator);
7862 }
7863 else {
7864 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7865 orderByComparator);
7866 }
7867 }
7868
7869 else {
7870 if (getDB().isSupportsInlineDistinct()) {
7871 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7872 }
7873 else {
7874 query.append(MBMessageModelImpl.ORDER_BY_SQL);
7875 }
7876 }
7877
7878 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7879 MBMessage.class.getName(), _FILTER_COLUMN_PK,
7880 _FILTER_COLUMN_USERID, groupId);
7881
7882 Session session = null;
7883
7884 try {
7885 session = openSession();
7886
7887 SQLQuery q = session.createSQLQuery(sql);
7888
7889 if (getDB().isSupportsInlineDistinct()) {
7890 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
7891 }
7892 else {
7893 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
7894 }
7895
7896 QueryPos qPos = QueryPos.getInstance(q);
7897
7898 qPos.add(groupId);
7899
7900 qPos.add(categoryId);
7901
7902 qPos.add(status);
7903
7904 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
7905 }
7906 catch (Exception e) {
7907 throw processException(e);
7908 }
7909 finally {
7910 closeSession(session);
7911 }
7912 }
7913
7914
7923 public List<MBMessage> findByC_C_S(long classNameId, long classPK,
7924 int status) throws SystemException {
7925 return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
7926 QueryUtil.ALL_POS, null);
7927 }
7928
7929
7944 public List<MBMessage> findByC_C_S(long classNameId, long classPK,
7945 int status, int start, int end) throws SystemException {
7946 return findByC_C_S(classNameId, classPK, status, start, end, null);
7947 }
7948
7949
7965 public List<MBMessage> findByC_C_S(long classNameId, long classPK,
7966 int status, int start, int end, OrderByComparator orderByComparator)
7967 throws SystemException {
7968 Object[] finderArgs = new Object[] {
7969 classNameId, classPK, status,
7970
7971 String.valueOf(start), String.valueOf(end),
7972 String.valueOf(orderByComparator)
7973 };
7974
7975 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_S,
7976 finderArgs, this);
7977
7978 if (list == null) {
7979 StringBundler query = null;
7980
7981 if (orderByComparator != null) {
7982 query = new StringBundler(5 +
7983 (orderByComparator.getOrderByFields().length * 3));
7984 }
7985 else {
7986 query = new StringBundler(5);
7987 }
7988
7989 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7990
7991 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
7992
7993 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
7994
7995 query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
7996
7997 if (orderByComparator != null) {
7998 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7999 orderByComparator);
8000 }
8001
8002 else {
8003 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8004 }
8005
8006 String sql = query.toString();
8007
8008 Session session = null;
8009
8010 try {
8011 session = openSession();
8012
8013 Query q = session.createQuery(sql);
8014
8015 QueryPos qPos = QueryPos.getInstance(q);
8016
8017 qPos.add(classNameId);
8018
8019 qPos.add(classPK);
8020
8021 qPos.add(status);
8022
8023 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8024 end);
8025 }
8026 catch (Exception e) {
8027 throw processException(e);
8028 }
8029 finally {
8030 if (list == null) {
8031 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_C_C_S,
8032 finderArgs);
8033 }
8034 else {
8035 cacheResult(list);
8036
8037 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_S,
8038 finderArgs, list);
8039 }
8040
8041 closeSession(session);
8042 }
8043 }
8044
8045 return list;
8046 }
8047
8048
8063 public MBMessage findByC_C_S_First(long classNameId, long classPK,
8064 int status, OrderByComparator orderByComparator)
8065 throws NoSuchMessageException, SystemException {
8066 List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
8067 orderByComparator);
8068
8069 if (list.isEmpty()) {
8070 StringBundler msg = new StringBundler(8);
8071
8072 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8073
8074 msg.append("classNameId=");
8075 msg.append(classNameId);
8076
8077 msg.append(", classPK=");
8078 msg.append(classPK);
8079
8080 msg.append(", status=");
8081 msg.append(status);
8082
8083 msg.append(StringPool.CLOSE_CURLY_BRACE);
8084
8085 throw new NoSuchMessageException(msg.toString());
8086 }
8087 else {
8088 return list.get(0);
8089 }
8090 }
8091
8092
8107 public MBMessage findByC_C_S_Last(long classNameId, long classPK,
8108 int status, OrderByComparator orderByComparator)
8109 throws NoSuchMessageException, SystemException {
8110 int count = countByC_C_S(classNameId, classPK, status);
8111
8112 List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
8113 count - 1, count, orderByComparator);
8114
8115 if (list.isEmpty()) {
8116 StringBundler msg = new StringBundler(8);
8117
8118 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8119
8120 msg.append("classNameId=");
8121 msg.append(classNameId);
8122
8123 msg.append(", classPK=");
8124 msg.append(classPK);
8125
8126 msg.append(", status=");
8127 msg.append(status);
8128
8129 msg.append(StringPool.CLOSE_CURLY_BRACE);
8130
8131 throw new NoSuchMessageException(msg.toString());
8132 }
8133 else {
8134 return list.get(0);
8135 }
8136 }
8137
8138
8154 public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
8155 long classNameId, long classPK, int status,
8156 OrderByComparator orderByComparator)
8157 throws NoSuchMessageException, SystemException {
8158 MBMessage mbMessage = findByPrimaryKey(messageId);
8159
8160 Session session = null;
8161
8162 try {
8163 session = openSession();
8164
8165 MBMessage[] array = new MBMessageImpl[3];
8166
8167 array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
8168 classPK, status, orderByComparator, true);
8169
8170 array[1] = mbMessage;
8171
8172 array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
8173 classPK, status, orderByComparator, false);
8174
8175 return array;
8176 }
8177 catch (Exception e) {
8178 throw processException(e);
8179 }
8180 finally {
8181 closeSession(session);
8182 }
8183 }
8184
8185 protected MBMessage getByC_C_S_PrevAndNext(Session session,
8186 MBMessage mbMessage, long classNameId, long classPK, int status,
8187 OrderByComparator orderByComparator, boolean previous) {
8188 StringBundler query = null;
8189
8190 if (orderByComparator != null) {
8191 query = new StringBundler(6 +
8192 (orderByComparator.getOrderByFields().length * 6));
8193 }
8194 else {
8195 query = new StringBundler(3);
8196 }
8197
8198 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8199
8200 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
8201
8202 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
8203
8204 query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
8205
8206 if (orderByComparator != null) {
8207 String[] orderByFields = orderByComparator.getOrderByFields();
8208
8209 if (orderByFields.length > 0) {
8210 query.append(WHERE_AND);
8211 }
8212
8213 for (int i = 0; i < orderByFields.length; i++) {
8214 query.append(_ORDER_BY_ENTITY_ALIAS);
8215 query.append(orderByFields[i]);
8216
8217 if ((i + 1) < orderByFields.length) {
8218 if (orderByComparator.isAscending() ^ previous) {
8219 query.append(WHERE_GREATER_THAN_HAS_NEXT);
8220 }
8221 else {
8222 query.append(WHERE_LESSER_THAN_HAS_NEXT);
8223 }
8224 }
8225 else {
8226 if (orderByComparator.isAscending() ^ previous) {
8227 query.append(WHERE_GREATER_THAN);
8228 }
8229 else {
8230 query.append(WHERE_LESSER_THAN);
8231 }
8232 }
8233 }
8234
8235 query.append(ORDER_BY_CLAUSE);
8236
8237 for (int i = 0; i < orderByFields.length; i++) {
8238 query.append(_ORDER_BY_ENTITY_ALIAS);
8239 query.append(orderByFields[i]);
8240
8241 if ((i + 1) < orderByFields.length) {
8242 if (orderByComparator.isAscending() ^ previous) {
8243 query.append(ORDER_BY_ASC_HAS_NEXT);
8244 }
8245 else {
8246 query.append(ORDER_BY_DESC_HAS_NEXT);
8247 }
8248 }
8249 else {
8250 if (orderByComparator.isAscending() ^ previous) {
8251 query.append(ORDER_BY_ASC);
8252 }
8253 else {
8254 query.append(ORDER_BY_DESC);
8255 }
8256 }
8257 }
8258 }
8259
8260 else {
8261 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8262 }
8263
8264 String sql = query.toString();
8265
8266 Query q = session.createQuery(sql);
8267
8268 q.setFirstResult(0);
8269 q.setMaxResults(2);
8270
8271 QueryPos qPos = QueryPos.getInstance(q);
8272
8273 qPos.add(classNameId);
8274
8275 qPos.add(classPK);
8276
8277 qPos.add(status);
8278
8279 if (orderByComparator != null) {
8280 Object[] values = orderByComparator.getOrderByValues(mbMessage);
8281
8282 for (Object value : values) {
8283 qPos.add(value);
8284 }
8285 }
8286
8287 List<MBMessage> list = q.list();
8288
8289 if (list.size() == 2) {
8290 return list.get(1);
8291 }
8292 else {
8293 return null;
8294 }
8295 }
8296
8297
8307 public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
8308 long threadId, int status) throws SystemException {
8309 return findByG_C_T_S(groupId, categoryId, threadId, status,
8310 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8311 }
8312
8313
8329 public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
8330 long threadId, int status, int start, int end)
8331 throws SystemException {
8332 return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
8333 null);
8334 }
8335
8336
8353 public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
8354 long threadId, int status, int start, int end,
8355 OrderByComparator orderByComparator) throws SystemException {
8356 Object[] finderArgs = new Object[] {
8357 groupId, categoryId, threadId, status,
8358
8359 String.valueOf(start), String.valueOf(end),
8360 String.valueOf(orderByComparator)
8361 };
8362
8363 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C_T_S,
8364 finderArgs, this);
8365
8366 if (list == null) {
8367 StringBundler query = null;
8368
8369 if (orderByComparator != null) {
8370 query = new StringBundler(6 +
8371 (orderByComparator.getOrderByFields().length * 3));
8372 }
8373 else {
8374 query = new StringBundler(6);
8375 }
8376
8377 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8378
8379 query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
8380
8381 query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
8382
8383 query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
8384
8385 query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
8386
8387 if (orderByComparator != null) {
8388 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8389 orderByComparator);
8390 }
8391
8392 else {
8393 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8394 }
8395
8396 String sql = query.toString();
8397
8398 Session session = null;
8399
8400 try {
8401 session = openSession();
8402
8403 Query q = session.createQuery(sql);
8404
8405 QueryPos qPos = QueryPos.getInstance(q);
8406
8407 qPos.add(groupId);
8408
8409 qPos.add(categoryId);
8410
8411 qPos.add(threadId);
8412
8413 qPos.add(status);
8414
8415 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
8416 end);
8417 }
8418 catch (Exception e) {
8419 throw processException(e);
8420 }
8421 finally {
8422 if (list == null) {
8423 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_C_T_S,
8424 finderArgs);
8425 }
8426 else {
8427 cacheResult(list);
8428
8429 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C_T_S,
8430 finderArgs, list);
8431 }
8432
8433 closeSession(session);
8434 }
8435 }
8436
8437 return list;
8438 }
8439
8440
8456 public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
8457 long threadId, int status, OrderByComparator orderByComparator)
8458 throws NoSuchMessageException, SystemException {
8459 List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
8460 status, 0, 1, orderByComparator);
8461
8462 if (list.isEmpty()) {
8463 StringBundler msg = new StringBundler(10);
8464
8465 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8466
8467 msg.append("groupId=");
8468 msg.append(groupId);
8469
8470 msg.append(", categoryId=");
8471 msg.append(categoryId);
8472
8473 msg.append(", threadId=");
8474 msg.append(threadId);
8475
8476 msg.append(", status=");
8477 msg.append(status);
8478
8479 msg.append(StringPool.CLOSE_CURLY_BRACE);
8480
8481 throw new NoSuchMessageException(msg.toString());
8482 }
8483 else {
8484 return list.get(0);
8485 }
8486 }
8487
8488
8504 public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
8505 long threadId, int status, OrderByComparator orderByComparator)
8506 throws NoSuchMessageException, SystemException {
8507 int count = countByG_C_T_S(groupId, categoryId, threadId, status);
8508
8509 List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
8510 status, count - 1, count, orderByComparator);
8511
8512 if (list.isEmpty()) {
8513 StringBundler msg = new StringBundler(10);
8514
8515 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8516
8517 msg.append("groupId=");
8518 msg.append(groupId);
8519
8520 msg.append(", categoryId=");
8521 msg.append(categoryId);
8522
8523 msg.append(", threadId=");
8524 msg.append(threadId);
8525
8526 msg.append(", status=");
8527 msg.append(status);
8528
8529 msg.append(StringPool.CLOSE_CURLY_BRACE);
8530
8531 throw new NoSuchMessageException(msg.toString());
8532 }
8533 else {
8534 return list.get(0);
8535 }
8536 }
8537
8538
8555 public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
8556 long categoryId, long threadId, int status,
8557 OrderByComparator orderByComparator)
8558 throws NoSuchMessageException, SystemException {
8559 MBMessage mbMessage = findByPrimaryKey(messageId);
8560
8561 Session session = null;
8562
8563 try {
8564 session = openSession();
8565
8566 MBMessage[] array = new MBMessageImpl[3];
8567
8568 array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
8569 categoryId, threadId, status, orderByComparator, true);
8570
8571 array[1] = mbMessage;
8572
8573 array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
8574 categoryId, threadId, status, orderByComparator, false);
8575
8576 return array;
8577 }
8578 catch (Exception e) {
8579 throw processException(e);
8580 }
8581 finally {
8582 closeSession(session);
8583 }
8584 }
8585
8586 protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
8587 MBMessage mbMessage, long groupId, long categoryId, long threadId,
8588 int status, OrderByComparator orderByComparator, boolean previous) {
8589 StringBundler query = null;
8590
8591 if (orderByComparator != null) {
8592 query = new StringBundler(6 +
8593 (orderByComparator.getOrderByFields().length * 6));
8594 }
8595 else {
8596 query = new StringBundler(3);
8597 }
8598
8599 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8600
8601 query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
8602
8603 query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
8604
8605 query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
8606
8607 query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
8608
8609 if (orderByComparator != null) {
8610 String[] orderByFields = orderByComparator.getOrderByFields();
8611
8612 if (orderByFields.length > 0) {
8613 query.append(WHERE_AND);
8614 }
8615
8616 for (int i = 0; i < orderByFields.length; i++) {
8617 query.append(_ORDER_BY_ENTITY_ALIAS);
8618 query.append(orderByFields[i]);
8619
8620 if ((i + 1) < orderByFields.length) {
8621 if (orderByComparator.isAscending() ^ previous) {
8622 query.append(WHERE_GREATER_THAN_HAS_NEXT);
8623 }
8624 else {
8625 query.append(WHERE_LESSER_THAN_HAS_NEXT);
8626 }
8627 }
8628 else {
8629 if (orderByComparator.isAscending() ^ previous) {
8630 query.append(WHERE_GREATER_THAN);
8631 }
8632 else {
8633 query.append(WHERE_LESSER_THAN);
8634 }
8635 }
8636 }
8637
8638 query.append(ORDER_BY_CLAUSE);
8639
8640 for (int i = 0; i < orderByFields.length; i++) {
8641 query.append(_ORDER_BY_ENTITY_ALIAS);
8642 query.append(orderByFields[i]);
8643
8644 if ((i + 1) < orderByFields.length) {
8645 if (orderByComparator.isAscending() ^ previous) {
8646 query.append(ORDER_BY_ASC_HAS_NEXT);
8647 }
8648 else {
8649 query.append(ORDER_BY_DESC_HAS_NEXT);
8650 }
8651 }
8652 else {
8653 if (orderByComparator.isAscending() ^ previous) {
8654 query.append(ORDER_BY_ASC);
8655 }
8656 else {
8657 query.append(ORDER_BY_DESC);
8658 }
8659 }
8660 }
8661 }
8662
8663 else {
8664 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8665 }
8666
8667 String sql = query.toString();
8668
8669 Query q = session.createQuery(sql);
8670
8671 q.setFirstResult(0);
8672 q.setMaxResults(2);
8673
8674 QueryPos qPos = QueryPos.getInstance(q);
8675
8676 qPos.add(groupId);
8677
8678 qPos.add(categoryId);
8679
8680 qPos.add(threadId);
8681
8682 qPos.add(status);
8683
8684 if (orderByComparator != null) {
8685 Object[] values = orderByComparator.getOrderByValues(mbMessage);
8686
8687 for (Object value : values) {
8688 qPos.add(value);
8689 }
8690 }
8691
8692 List<MBMessage> list = q.list();
8693
8694 if (list.size() == 2) {
8695 return list.get(1);
8696 }
8697 else {
8698 return null;
8699 }
8700 }
8701
8702
8712 public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
8713 long threadId, int status) throws SystemException {
8714 return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
8715 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8716 }
8717
8718
8734 public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
8735 long threadId, int status, int start, int end)
8736 throws SystemException {
8737 return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
8738 start, end, null);
8739 }
8740
8741
8758 public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
8759 long threadId, int status, int start, int end,
8760 OrderByComparator orderByComparator) throws SystemException {
8761 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8762 return findByG_C_T_S(groupId, categoryId, threadId, status, start,
8763 end, orderByComparator);
8764 }
8765
8766 StringBundler query = null;
8767
8768 if (orderByComparator != null) {
8769 query = new StringBundler(6 +
8770 (orderByComparator.getOrderByFields().length * 3));
8771 }
8772 else {
8773 query = new StringBundler(6);
8774 }
8775
8776 if (getDB().isSupportsInlineDistinct()) {
8777 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
8778 }
8779 else {
8780 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
8781 }
8782
8783 query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
8784
8785 query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
8786
8787 query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
8788
8789 query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
8790
8791 if (!getDB().isSupportsInlineDistinct()) {
8792 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
8793 }
8794
8795 if (orderByComparator != null) {
8796 if (getDB().isSupportsInlineDistinct()) {
8797 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8798 orderByComparator);
8799 }
8800 else {
8801 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8802 orderByComparator);
8803 }
8804 }
8805
8806 else {
8807 if (getDB().isSupportsInlineDistinct()) {
8808 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8809 }
8810 else {
8811 query.append(MBMessageModelImpl.ORDER_BY_SQL);
8812 }
8813 }
8814
8815 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8816 MBMessage.class.getName(), _FILTER_COLUMN_PK,
8817 _FILTER_COLUMN_USERID, groupId);
8818
8819 Session session = null;
8820
8821 try {
8822 session = openSession();
8823
8824 SQLQuery q = session.createSQLQuery(sql);
8825
8826 if (getDB().isSupportsInlineDistinct()) {
8827 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
8828 }
8829 else {
8830 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
8831 }
8832
8833 QueryPos qPos = QueryPos.getInstance(q);
8834
8835 qPos.add(groupId);
8836
8837 qPos.add(categoryId);
8838
8839 qPos.add(threadId);
8840
8841 qPos.add(status);
8842
8843 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
8844 }
8845 catch (Exception e) {
8846 throw processException(e);
8847 }
8848 finally {
8849 closeSession(session);
8850 }
8851 }
8852
8853
8859 public List<MBMessage> findAll() throws SystemException {
8860 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8861 }
8862
8863
8875 public List<MBMessage> findAll(int start, int end)
8876 throws SystemException {
8877 return findAll(start, end, null);
8878 }
8879
8880
8893 public List<MBMessage> findAll(int start, int end,
8894 OrderByComparator orderByComparator) throws SystemException {
8895 Object[] finderArgs = new Object[] {
8896 String.valueOf(start), String.valueOf(end),
8897 String.valueOf(orderByComparator)
8898 };
8899
8900 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
8901 finderArgs, this);
8902
8903 if (list == null) {
8904 StringBundler query = null;
8905 String sql = null;
8906
8907 if (orderByComparator != null) {
8908 query = new StringBundler(2 +
8909 (orderByComparator.getOrderByFields().length * 3));
8910
8911 query.append(_SQL_SELECT_MBMESSAGE);
8912
8913 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8914 orderByComparator);
8915
8916 sql = query.toString();
8917 }
8918 else {
8919 sql = _SQL_SELECT_MBMESSAGE.concat(MBMessageModelImpl.ORDER_BY_JPQL);
8920 }
8921
8922 Session session = null;
8923
8924 try {
8925 session = openSession();
8926
8927 Query q = session.createQuery(sql);
8928
8929 if (orderByComparator == null) {
8930 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8931 start, end, false);
8932
8933 Collections.sort(list);
8934 }
8935 else {
8936 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8937 start, end);
8938 }
8939 }
8940 catch (Exception e) {
8941 throw processException(e);
8942 }
8943 finally {
8944 if (list == null) {
8945 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
8946 finderArgs);
8947 }
8948 else {
8949 cacheResult(list);
8950
8951 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
8952 list);
8953 }
8954
8955 closeSession(session);
8956 }
8957 }
8958
8959 return list;
8960 }
8961
8962
8968 public void removeByUuid(String uuid) throws SystemException {
8969 for (MBMessage mbMessage : findByUuid(uuid)) {
8970 remove(mbMessage);
8971 }
8972 }
8973
8974
8981 public void removeByUUID_G(String uuid, long groupId)
8982 throws NoSuchMessageException, SystemException {
8983 MBMessage mbMessage = findByUUID_G(uuid, groupId);
8984
8985 remove(mbMessage);
8986 }
8987
8988
8994 public void removeByGroupId(long groupId) throws SystemException {
8995 for (MBMessage mbMessage : findByGroupId(groupId)) {
8996 remove(mbMessage);
8997 }
8998 }
8999
9000
9006 public void removeByCompanyId(long companyId) throws SystemException {
9007 for (MBMessage mbMessage : findByCompanyId(companyId)) {
9008 remove(mbMessage);
9009 }
9010 }
9011
9012
9018 public void removeByThreadId(long threadId) throws SystemException {
9019 for (MBMessage mbMessage : findByThreadId(threadId)) {
9020 remove(mbMessage);
9021 }
9022 }
9023
9024
9030 public void removeByThreadReplies(long threadId) throws SystemException {
9031 for (MBMessage mbMessage : findByThreadReplies(threadId)) {
9032 remove(mbMessage);
9033 }
9034 }
9035
9036
9042 public void removeByUserId(long userId) throws SystemException {
9043 for (MBMessage mbMessage : findByUserId(userId)) {
9044 remove(mbMessage);
9045 }
9046 }
9047
9048
9055 public void removeByG_U(long groupId, long userId)
9056 throws SystemException {
9057 for (MBMessage mbMessage : findByG_U(groupId, userId)) {
9058 remove(mbMessage);
9059 }
9060 }
9061
9062
9069 public void removeByG_C(long groupId, long categoryId)
9070 throws SystemException {
9071 for (MBMessage mbMessage : findByG_C(groupId, categoryId)) {
9072 remove(mbMessage);
9073 }
9074 }
9075
9076
9083 public void removeByG_S(long groupId, int status) throws SystemException {
9084 for (MBMessage mbMessage : findByG_S(groupId, status)) {
9085 remove(mbMessage);
9086 }
9087 }
9088
9089
9096 public void removeByC_S(long companyId, int status)
9097 throws SystemException {
9098 for (MBMessage mbMessage : findByC_S(companyId, status)) {
9099 remove(mbMessage);
9100 }
9101 }
9102
9103
9110 public void removeByC_C(long classNameId, long classPK)
9111 throws SystemException {
9112 for (MBMessage mbMessage : findByC_C(classNameId, classPK)) {
9113 remove(mbMessage);
9114 }
9115 }
9116
9117
9124 public void removeByT_P(long threadId, long parentMessageId)
9125 throws SystemException {
9126 for (MBMessage mbMessage : findByT_P(threadId, parentMessageId)) {
9127 remove(mbMessage);
9128 }
9129 }
9130
9131
9138 public void removeByT_S(long threadId, int status)
9139 throws SystemException {
9140 for (MBMessage mbMessage : findByT_S(threadId, status)) {
9141 remove(mbMessage);
9142 }
9143 }
9144
9145
9152 public void removeByTR_S(long threadId, int status)
9153 throws SystemException {
9154 for (MBMessage mbMessage : findByTR_S(threadId, status)) {
9155 remove(mbMessage);
9156 }
9157 }
9158
9159
9167 public void removeByG_U_S(long groupId, long userId, int status)
9168 throws SystemException {
9169 for (MBMessage mbMessage : findByG_U_S(groupId, userId, status)) {
9170 remove(mbMessage);
9171 }
9172 }
9173
9174
9182 public void removeByG_C_T(long groupId, long categoryId, long threadId)
9183 throws SystemException {
9184 for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId)) {
9185 remove(mbMessage);
9186 }
9187 }
9188
9189
9197 public void removeByG_C_S(long groupId, long categoryId, int status)
9198 throws SystemException {
9199 for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status)) {
9200 remove(mbMessage);
9201 }
9202 }
9203
9204
9212 public void removeByC_C_S(long classNameId, long classPK, int status)
9213 throws SystemException {
9214 for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status)) {
9215 remove(mbMessage);
9216 }
9217 }
9218
9219
9228 public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
9229 int status) throws SystemException {
9230 for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
9231 status)) {
9232 remove(mbMessage);
9233 }
9234 }
9235
9236
9241 public void removeAll() throws SystemException {
9242 for (MBMessage mbMessage : findAll()) {
9243 remove(mbMessage);
9244 }
9245 }
9246
9247
9254 public int countByUuid(String uuid) throws SystemException {
9255 Object[] finderArgs = new Object[] { uuid };
9256
9257 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
9258 finderArgs, this);
9259
9260 if (count == null) {
9261 StringBundler query = new StringBundler(2);
9262
9263 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9264
9265 if (uuid == null) {
9266 query.append(_FINDER_COLUMN_UUID_UUID_1);
9267 }
9268 else {
9269 if (uuid.equals(StringPool.BLANK)) {
9270 query.append(_FINDER_COLUMN_UUID_UUID_3);
9271 }
9272 else {
9273 query.append(_FINDER_COLUMN_UUID_UUID_2);
9274 }
9275 }
9276
9277 String sql = query.toString();
9278
9279 Session session = null;
9280
9281 try {
9282 session = openSession();
9283
9284 Query q = session.createQuery(sql);
9285
9286 QueryPos qPos = QueryPos.getInstance(q);
9287
9288 if (uuid != null) {
9289 qPos.add(uuid);
9290 }
9291
9292 count = (Long)q.uniqueResult();
9293 }
9294 catch (Exception e) {
9295 throw processException(e);
9296 }
9297 finally {
9298 if (count == null) {
9299 count = Long.valueOf(0);
9300 }
9301
9302 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
9303 finderArgs, count);
9304
9305 closeSession(session);
9306 }
9307 }
9308
9309 return count.intValue();
9310 }
9311
9312
9320 public int countByUUID_G(String uuid, long groupId)
9321 throws SystemException {
9322 Object[] finderArgs = new Object[] { uuid, groupId };
9323
9324 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
9325 finderArgs, this);
9326
9327 if (count == null) {
9328 StringBundler query = new StringBundler(3);
9329
9330 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9331
9332 if (uuid == null) {
9333 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
9334 }
9335 else {
9336 if (uuid.equals(StringPool.BLANK)) {
9337 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
9338 }
9339 else {
9340 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
9341 }
9342 }
9343
9344 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
9345
9346 String sql = query.toString();
9347
9348 Session session = null;
9349
9350 try {
9351 session = openSession();
9352
9353 Query q = session.createQuery(sql);
9354
9355 QueryPos qPos = QueryPos.getInstance(q);
9356
9357 if (uuid != null) {
9358 qPos.add(uuid);
9359 }
9360
9361 qPos.add(groupId);
9362
9363 count = (Long)q.uniqueResult();
9364 }
9365 catch (Exception e) {
9366 throw processException(e);
9367 }
9368 finally {
9369 if (count == null) {
9370 count = Long.valueOf(0);
9371 }
9372
9373 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
9374 finderArgs, count);
9375
9376 closeSession(session);
9377 }
9378 }
9379
9380 return count.intValue();
9381 }
9382
9383
9390 public int countByGroupId(long groupId) throws SystemException {
9391 Object[] finderArgs = new Object[] { groupId };
9392
9393 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
9394 finderArgs, this);
9395
9396 if (count == null) {
9397 StringBundler query = new StringBundler(2);
9398
9399 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9400
9401 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
9402
9403 String sql = query.toString();
9404
9405 Session session = null;
9406
9407 try {
9408 session = openSession();
9409
9410 Query q = session.createQuery(sql);
9411
9412 QueryPos qPos = QueryPos.getInstance(q);
9413
9414 qPos.add(groupId);
9415
9416 count = (Long)q.uniqueResult();
9417 }
9418 catch (Exception e) {
9419 throw processException(e);
9420 }
9421 finally {
9422 if (count == null) {
9423 count = Long.valueOf(0);
9424 }
9425
9426 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
9427 finderArgs, count);
9428
9429 closeSession(session);
9430 }
9431 }
9432
9433 return count.intValue();
9434 }
9435
9436
9443 public int filterCountByGroupId(long groupId) throws SystemException {
9444 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9445 return countByGroupId(groupId);
9446 }
9447
9448 StringBundler query = new StringBundler(2);
9449
9450 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
9451
9452 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
9453
9454 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9455 MBMessage.class.getName(), _FILTER_COLUMN_PK,
9456 _FILTER_COLUMN_USERID, groupId);
9457
9458 Session session = null;
9459
9460 try {
9461 session = openSession();
9462
9463 SQLQuery q = session.createSQLQuery(sql);
9464
9465 q.addScalar(COUNT_COLUMN_NAME,
9466 com.liferay.portal.kernel.dao.orm.Type.LONG);
9467
9468 QueryPos qPos = QueryPos.getInstance(q);
9469
9470 qPos.add(groupId);
9471
9472 Long count = (Long)q.uniqueResult();
9473
9474 return count.intValue();
9475 }
9476 catch (Exception e) {
9477 throw processException(e);
9478 }
9479 finally {
9480 closeSession(session);
9481 }
9482 }
9483
9484
9491 public int countByCompanyId(long companyId) throws SystemException {
9492 Object[] finderArgs = new Object[] { companyId };
9493
9494 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
9495 finderArgs, this);
9496
9497 if (count == null) {
9498 StringBundler query = new StringBundler(2);
9499
9500 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9501
9502 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
9503
9504 String sql = query.toString();
9505
9506 Session session = null;
9507
9508 try {
9509 session = openSession();
9510
9511 Query q = session.createQuery(sql);
9512
9513 QueryPos qPos = QueryPos.getInstance(q);
9514
9515 qPos.add(companyId);
9516
9517 count = (Long)q.uniqueResult();
9518 }
9519 catch (Exception e) {
9520 throw processException(e);
9521 }
9522 finally {
9523 if (count == null) {
9524 count = Long.valueOf(0);
9525 }
9526
9527 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
9528 finderArgs, count);
9529
9530 closeSession(session);
9531 }
9532 }
9533
9534 return count.intValue();
9535 }
9536
9537
9544 public int countByThreadId(long threadId) throws SystemException {
9545 Object[] finderArgs = new Object[] { threadId };
9546
9547 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
9548 finderArgs, this);
9549
9550 if (count == null) {
9551 StringBundler query = new StringBundler(2);
9552
9553 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9554
9555 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
9556
9557 String sql = query.toString();
9558
9559 Session session = null;
9560
9561 try {
9562 session = openSession();
9563
9564 Query q = session.createQuery(sql);
9565
9566 QueryPos qPos = QueryPos.getInstance(q);
9567
9568 qPos.add(threadId);
9569
9570 count = (Long)q.uniqueResult();
9571 }
9572 catch (Exception e) {
9573 throw processException(e);
9574 }
9575 finally {
9576 if (count == null) {
9577 count = Long.valueOf(0);
9578 }
9579
9580 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
9581 finderArgs, count);
9582
9583 closeSession(session);
9584 }
9585 }
9586
9587 return count.intValue();
9588 }
9589
9590
9597 public int countByThreadReplies(long threadId) throws SystemException {
9598 Object[] finderArgs = new Object[] { threadId };
9599
9600 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
9601 finderArgs, this);
9602
9603 if (count == null) {
9604 StringBundler query = new StringBundler(2);
9605
9606 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9607
9608 query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
9609
9610 String sql = query.toString();
9611
9612 Session session = null;
9613
9614 try {
9615 session = openSession();
9616
9617 Query q = session.createQuery(sql);
9618
9619 QueryPos qPos = QueryPos.getInstance(q);
9620
9621 qPos.add(threadId);
9622
9623 count = (Long)q.uniqueResult();
9624 }
9625 catch (Exception e) {
9626 throw processException(e);
9627 }
9628 finally {
9629 if (count == null) {
9630 count = Long.valueOf(0);
9631 }
9632
9633 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
9634 finderArgs, count);
9635
9636 closeSession(session);
9637 }
9638 }
9639
9640 return count.intValue();
9641 }
9642
9643
9650 public int countByUserId(long userId) throws SystemException {
9651 Object[] finderArgs = new Object[] { userId };
9652
9653 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
9654 finderArgs, this);
9655
9656 if (count == null) {
9657 StringBundler query = new StringBundler(2);
9658
9659 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9660
9661 query.append(_FINDER_COLUMN_USERID_USERID_2);
9662
9663 String sql = query.toString();
9664
9665 Session session = null;
9666
9667 try {
9668 session = openSession();
9669
9670 Query q = session.createQuery(sql);
9671
9672 QueryPos qPos = QueryPos.getInstance(q);
9673
9674 qPos.add(userId);
9675
9676 count = (Long)q.uniqueResult();
9677 }
9678 catch (Exception e) {
9679 throw processException(e);
9680 }
9681 finally {
9682 if (count == null) {
9683 count = Long.valueOf(0);
9684 }
9685
9686 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
9687 finderArgs, count);
9688
9689 closeSession(session);
9690 }
9691 }
9692
9693 return count.intValue();
9694 }
9695
9696
9704 public int countByG_U(long groupId, long userId) throws SystemException {
9705 Object[] finderArgs = new Object[] { groupId, userId };
9706
9707 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
9708 finderArgs, this);
9709
9710 if (count == null) {
9711 StringBundler query = new StringBundler(3);
9712
9713 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9714
9715 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
9716
9717 query.append(_FINDER_COLUMN_G_U_USERID_2);
9718
9719 String sql = query.toString();
9720
9721 Session session = null;
9722
9723 try {
9724 session = openSession();
9725
9726 Query q = session.createQuery(sql);
9727
9728 QueryPos qPos = QueryPos.getInstance(q);
9729
9730 qPos.add(groupId);
9731
9732 qPos.add(userId);
9733
9734 count = (Long)q.uniqueResult();
9735 }
9736 catch (Exception e) {
9737 throw processException(e);
9738 }
9739 finally {
9740 if (count == null) {
9741 count = Long.valueOf(0);
9742 }
9743
9744 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
9745 count);
9746
9747 closeSession(session);
9748 }
9749 }
9750
9751 return count.intValue();
9752 }
9753
9754
9762 public int filterCountByG_U(long groupId, long userId)
9763 throws SystemException {
9764 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9765 return countByG_U(groupId, userId);
9766 }
9767
9768 StringBundler query = new StringBundler(3);
9769
9770 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
9771
9772 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
9773
9774 query.append(_FINDER_COLUMN_G_U_USERID_2);
9775
9776 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9777 MBMessage.class.getName(), _FILTER_COLUMN_PK,
9778 _FILTER_COLUMN_USERID, groupId);
9779
9780 Session session = null;
9781
9782 try {
9783 session = openSession();
9784
9785 SQLQuery q = session.createSQLQuery(sql);
9786
9787 q.addScalar(COUNT_COLUMN_NAME,
9788 com.liferay.portal.kernel.dao.orm.Type.LONG);
9789
9790 QueryPos qPos = QueryPos.getInstance(q);
9791
9792 qPos.add(groupId);
9793
9794 qPos.add(userId);
9795
9796 Long count = (Long)q.uniqueResult();
9797
9798 return count.intValue();
9799 }
9800 catch (Exception e) {
9801 throw processException(e);
9802 }
9803 finally {
9804 closeSession(session);
9805 }
9806 }
9807
9808
9816 public int countByG_C(long groupId, long categoryId)
9817 throws SystemException {
9818 Object[] finderArgs = new Object[] { groupId, categoryId };
9819
9820 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
9821 finderArgs, this);
9822
9823 if (count == null) {
9824 StringBundler query = new StringBundler(3);
9825
9826 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9827
9828 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
9829
9830 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
9831
9832 String sql = query.toString();
9833
9834 Session session = null;
9835
9836 try {
9837 session = openSession();
9838
9839 Query q = session.createQuery(sql);
9840
9841 QueryPos qPos = QueryPos.getInstance(q);
9842
9843 qPos.add(groupId);
9844
9845 qPos.add(categoryId);
9846
9847 count = (Long)q.uniqueResult();
9848 }
9849 catch (Exception e) {
9850 throw processException(e);
9851 }
9852 finally {
9853 if (count == null) {
9854 count = Long.valueOf(0);
9855 }
9856
9857 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
9858 count);
9859
9860 closeSession(session);
9861 }
9862 }
9863
9864 return count.intValue();
9865 }
9866
9867
9875 public int filterCountByG_C(long groupId, long categoryId)
9876 throws SystemException {
9877 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9878 return countByG_C(groupId, categoryId);
9879 }
9880
9881 StringBundler query = new StringBundler(3);
9882
9883 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
9884
9885 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
9886
9887 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
9888
9889 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9890 MBMessage.class.getName(), _FILTER_COLUMN_PK,
9891 _FILTER_COLUMN_USERID, groupId);
9892
9893 Session session = null;
9894
9895 try {
9896 session = openSession();
9897
9898 SQLQuery q = session.createSQLQuery(sql);
9899
9900 q.addScalar(COUNT_COLUMN_NAME,
9901 com.liferay.portal.kernel.dao.orm.Type.LONG);
9902
9903 QueryPos qPos = QueryPos.getInstance(q);
9904
9905 qPos.add(groupId);
9906
9907 qPos.add(categoryId);
9908
9909 Long count = (Long)q.uniqueResult();
9910
9911 return count.intValue();
9912 }
9913 catch (Exception e) {
9914 throw processException(e);
9915 }
9916 finally {
9917 closeSession(session);
9918 }
9919 }
9920
9921
9929 public int countByG_S(long groupId, int status) throws SystemException {
9930 Object[] finderArgs = new Object[] { groupId, status };
9931
9932 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
9933 finderArgs, this);
9934
9935 if (count == null) {
9936 StringBundler query = new StringBundler(3);
9937
9938 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9939
9940 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
9941
9942 query.append(_FINDER_COLUMN_G_S_STATUS_2);
9943
9944 String sql = query.toString();
9945
9946 Session session = null;
9947
9948 try {
9949 session = openSession();
9950
9951 Query q = session.createQuery(sql);
9952
9953 QueryPos qPos = QueryPos.getInstance(q);
9954
9955 qPos.add(groupId);
9956
9957 qPos.add(status);
9958
9959 count = (Long)q.uniqueResult();
9960 }
9961 catch (Exception e) {
9962 throw processException(e);
9963 }
9964 finally {
9965 if (count == null) {
9966 count = Long.valueOf(0);
9967 }
9968
9969 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
9970 count);
9971
9972 closeSession(session);
9973 }
9974 }
9975
9976 return count.intValue();
9977 }
9978
9979
9987 public int filterCountByG_S(long groupId, int status)
9988 throws SystemException {
9989 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9990 return countByG_S(groupId, status);
9991 }
9992
9993 StringBundler query = new StringBundler(3);
9994
9995 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
9996
9997 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
9998
9999 query.append(_FINDER_COLUMN_G_S_STATUS_2);
10000
10001 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10002 MBMessage.class.getName(), _FILTER_COLUMN_PK,
10003 _FILTER_COLUMN_USERID, groupId);
10004
10005 Session session = null;
10006
10007 try {
10008 session = openSession();
10009
10010 SQLQuery q = session.createSQLQuery(sql);
10011
10012 q.addScalar(COUNT_COLUMN_NAME,
10013 com.liferay.portal.kernel.dao.orm.Type.LONG);
10014
10015 QueryPos qPos = QueryPos.getInstance(q);
10016
10017 qPos.add(groupId);
10018
10019 qPos.add(status);
10020
10021 Long count = (Long)q.uniqueResult();
10022
10023 return count.intValue();
10024 }
10025 catch (Exception e) {
10026 throw processException(e);
10027 }
10028 finally {
10029 closeSession(session);
10030 }
10031 }
10032
10033
10041 public int countByC_S(long companyId, int status) throws SystemException {
10042 Object[] finderArgs = new Object[] { companyId, status };
10043
10044 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_S,
10045 finderArgs, this);
10046
10047 if (count == null) {
10048 StringBundler query = new StringBundler(3);
10049
10050 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10051
10052 query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
10053
10054 query.append(_FINDER_COLUMN_C_S_STATUS_2);
10055
10056 String sql = query.toString();
10057
10058 Session session = null;
10059
10060 try {
10061 session = openSession();
10062
10063 Query q = session.createQuery(sql);
10064
10065 QueryPos qPos = QueryPos.getInstance(q);
10066
10067 qPos.add(companyId);
10068
10069 qPos.add(status);
10070
10071 count = (Long)q.uniqueResult();
10072 }
10073 catch (Exception e) {
10074 throw processException(e);
10075 }
10076 finally {
10077 if (count == null) {
10078 count = Long.valueOf(0);
10079 }
10080
10081 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_S, finderArgs,
10082 count);
10083
10084 closeSession(session);
10085 }
10086 }
10087
10088 return count.intValue();
10089 }
10090
10091
10099 public int countByC_C(long classNameId, long classPK)
10100 throws SystemException {
10101 Object[] finderArgs = new Object[] { classNameId, classPK };
10102
10103 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
10104 finderArgs, this);
10105
10106 if (count == null) {
10107 StringBundler query = new StringBundler(3);
10108
10109 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10110
10111 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
10112
10113 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
10114
10115 String sql = query.toString();
10116
10117 Session session = null;
10118
10119 try {
10120 session = openSession();
10121
10122 Query q = session.createQuery(sql);
10123
10124 QueryPos qPos = QueryPos.getInstance(q);
10125
10126 qPos.add(classNameId);
10127
10128 qPos.add(classPK);
10129
10130 count = (Long)q.uniqueResult();
10131 }
10132 catch (Exception e) {
10133 throw processException(e);
10134 }
10135 finally {
10136 if (count == null) {
10137 count = Long.valueOf(0);
10138 }
10139
10140 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
10141 count);
10142
10143 closeSession(session);
10144 }
10145 }
10146
10147 return count.intValue();
10148 }
10149
10150
10158 public int countByT_P(long threadId, long parentMessageId)
10159 throws SystemException {
10160 Object[] finderArgs = new Object[] { threadId, parentMessageId };
10161
10162 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_P,
10163 finderArgs, this);
10164
10165 if (count == null) {
10166 StringBundler query = new StringBundler(3);
10167
10168 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10169
10170 query.append(_FINDER_COLUMN_T_P_THREADID_2);
10171
10172 query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
10173
10174 String sql = query.toString();
10175
10176 Session session = null;
10177
10178 try {
10179 session = openSession();
10180
10181 Query q = session.createQuery(sql);
10182
10183 QueryPos qPos = QueryPos.getInstance(q);
10184
10185 qPos.add(threadId);
10186
10187 qPos.add(parentMessageId);
10188
10189 count = (Long)q.uniqueResult();
10190 }
10191 catch (Exception e) {
10192 throw processException(e);
10193 }
10194 finally {
10195 if (count == null) {
10196 count = Long.valueOf(0);
10197 }
10198
10199 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_P, finderArgs,
10200 count);
10201
10202 closeSession(session);
10203 }
10204 }
10205
10206 return count.intValue();
10207 }
10208
10209
10217 public int countByT_S(long threadId, int status) throws SystemException {
10218 Object[] finderArgs = new Object[] { threadId, status };
10219
10220 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_S,
10221 finderArgs, this);
10222
10223 if (count == null) {
10224 StringBundler query = new StringBundler(3);
10225
10226 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10227
10228 query.append(_FINDER_COLUMN_T_S_THREADID_2);
10229
10230 query.append(_FINDER_COLUMN_T_S_STATUS_2);
10231
10232 String sql = query.toString();
10233
10234 Session session = null;
10235
10236 try {
10237 session = openSession();
10238
10239 Query q = session.createQuery(sql);
10240
10241 QueryPos qPos = QueryPos.getInstance(q);
10242
10243 qPos.add(threadId);
10244
10245 qPos.add(status);
10246
10247 count = (Long)q.uniqueResult();
10248 }
10249 catch (Exception e) {
10250 throw processException(e);
10251 }
10252 finally {
10253 if (count == null) {
10254 count = Long.valueOf(0);
10255 }
10256
10257 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_S, finderArgs,
10258 count);
10259
10260 closeSession(session);
10261 }
10262 }
10263
10264 return count.intValue();
10265 }
10266
10267
10275 public int countByTR_S(long threadId, int status) throws SystemException {
10276 Object[] finderArgs = new Object[] { threadId, status };
10277
10278 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TR_S,
10279 finderArgs, this);
10280
10281 if (count == null) {
10282 StringBundler query = new StringBundler(3);
10283
10284 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10285
10286 query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10287
10288 query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10289
10290 String sql = query.toString();
10291
10292 Session session = null;
10293
10294 try {
10295 session = openSession();
10296
10297 Query q = session.createQuery(sql);
10298
10299 QueryPos qPos = QueryPos.getInstance(q);
10300
10301 qPos.add(threadId);
10302
10303 qPos.add(status);
10304
10305 count = (Long)q.uniqueResult();
10306 }
10307 catch (Exception e) {
10308 throw processException(e);
10309 }
10310 finally {
10311 if (count == null) {
10312 count = Long.valueOf(0);
10313 }
10314
10315 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TR_S,
10316 finderArgs, count);
10317
10318 closeSession(session);
10319 }
10320 }
10321
10322 return count.intValue();
10323 }
10324
10325
10334 public int countByG_U_S(long groupId, long userId, int status)
10335 throws SystemException {
10336 Object[] finderArgs = new Object[] { groupId, userId, status };
10337
10338 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_S,
10339 finderArgs, this);
10340
10341 if (count == null) {
10342 StringBundler query = new StringBundler(4);
10343
10344 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10345
10346 query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10347
10348 query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10349
10350 query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10351
10352 String sql = query.toString();
10353
10354 Session session = null;
10355
10356 try {
10357 session = openSession();
10358
10359 Query q = session.createQuery(sql);
10360
10361 QueryPos qPos = QueryPos.getInstance(q);
10362
10363 qPos.add(groupId);
10364
10365 qPos.add(userId);
10366
10367 qPos.add(status);
10368
10369 count = (Long)q.uniqueResult();
10370 }
10371 catch (Exception e) {
10372 throw processException(e);
10373 }
10374 finally {
10375 if (count == null) {
10376 count = Long.valueOf(0);
10377 }
10378
10379 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_S,
10380 finderArgs, count);
10381
10382 closeSession(session);
10383 }
10384 }
10385
10386 return count.intValue();
10387 }
10388
10389
10398 public int filterCountByG_U_S(long groupId, long userId, int status)
10399 throws SystemException {
10400 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10401 return countByG_U_S(groupId, userId, status);
10402 }
10403
10404 StringBundler query = new StringBundler(4);
10405
10406 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
10407
10408 query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10409
10410 query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10411
10412 query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10413
10414 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10415 MBMessage.class.getName(), _FILTER_COLUMN_PK,
10416 _FILTER_COLUMN_USERID, groupId);
10417
10418 Session session = null;
10419
10420 try {
10421 session = openSession();
10422
10423 SQLQuery q = session.createSQLQuery(sql);
10424
10425 q.addScalar(COUNT_COLUMN_NAME,
10426 com.liferay.portal.kernel.dao.orm.Type.LONG);
10427
10428 QueryPos qPos = QueryPos.getInstance(q);
10429
10430 qPos.add(groupId);
10431
10432 qPos.add(userId);
10433
10434 qPos.add(status);
10435
10436 Long count = (Long)q.uniqueResult();
10437
10438 return count.intValue();
10439 }
10440 catch (Exception e) {
10441 throw processException(e);
10442 }
10443 finally {
10444 closeSession(session);
10445 }
10446 }
10447
10448
10457 public int countByG_C_T(long groupId, long categoryId, long threadId)
10458 throws SystemException {
10459 Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
10460
10461 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T,
10462 finderArgs, this);
10463
10464 if (count == null) {
10465 StringBundler query = new StringBundler(4);
10466
10467 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10468
10469 query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10470
10471 query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10472
10473 query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10474
10475 String sql = query.toString();
10476
10477 Session session = null;
10478
10479 try {
10480 session = openSession();
10481
10482 Query q = session.createQuery(sql);
10483
10484 QueryPos qPos = QueryPos.getInstance(q);
10485
10486 qPos.add(groupId);
10487
10488 qPos.add(categoryId);
10489
10490 qPos.add(threadId);
10491
10492 count = (Long)q.uniqueResult();
10493 }
10494 catch (Exception e) {
10495 throw processException(e);
10496 }
10497 finally {
10498 if (count == null) {
10499 count = Long.valueOf(0);
10500 }
10501
10502 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T,
10503 finderArgs, count);
10504
10505 closeSession(session);
10506 }
10507 }
10508
10509 return count.intValue();
10510 }
10511
10512
10521 public int filterCountByG_C_T(long groupId, long categoryId, long threadId)
10522 throws SystemException {
10523 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10524 return countByG_C_T(groupId, categoryId, threadId);
10525 }
10526
10527 StringBundler query = new StringBundler(4);
10528
10529 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
10530
10531 query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
10532
10533 query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
10534
10535 query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
10536
10537 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10538 MBMessage.class.getName(), _FILTER_COLUMN_PK,
10539 _FILTER_COLUMN_USERID, groupId);
10540
10541 Session session = null;
10542
10543 try {
10544 session = openSession();
10545
10546 SQLQuery q = session.createSQLQuery(sql);
10547
10548 q.addScalar(COUNT_COLUMN_NAME,
10549 com.liferay.portal.kernel.dao.orm.Type.LONG);
10550
10551 QueryPos qPos = QueryPos.getInstance(q);
10552
10553 qPos.add(groupId);
10554
10555 qPos.add(categoryId);
10556
10557 qPos.add(threadId);
10558
10559 Long count = (Long)q.uniqueResult();
10560
10561 return count.intValue();
10562 }
10563 catch (Exception e) {
10564 throw processException(e);
10565 }
10566 finally {
10567 closeSession(session);
10568 }
10569 }
10570
10571
10580 public int countByG_C_S(long groupId, long categoryId, int status)
10581 throws SystemException {
10582 Object[] finderArgs = new Object[] { groupId, categoryId, status };
10583
10584 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_S,
10585 finderArgs, this);
10586
10587 if (count == null) {
10588 StringBundler query = new StringBundler(4);
10589
10590 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10591
10592 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
10593
10594 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
10595
10596 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
10597
10598 String sql = query.toString();
10599
10600 Session session = null;
10601
10602 try {
10603 session = openSession();
10604
10605 Query q = session.createQuery(sql);
10606
10607 QueryPos qPos = QueryPos.getInstance(q);
10608
10609 qPos.add(groupId);
10610
10611 qPos.add(categoryId);
10612
10613 qPos.add(status);
10614
10615 count = (Long)q.uniqueResult();
10616 }
10617 catch (Exception e) {
10618 throw processException(e);
10619 }
10620 finally {
10621 if (count == null) {
10622 count = Long.valueOf(0);
10623 }
10624
10625 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S,
10626 finderArgs, count);
10627
10628 closeSession(session);
10629 }
10630 }
10631
10632 return count.intValue();
10633 }
10634
10635
10644 public int filterCountByG_C_S(long groupId, long categoryId, int status)
10645 throws SystemException {
10646 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10647 return countByG_C_S(groupId, categoryId, status);
10648 }
10649
10650 StringBundler query = new StringBundler(4);
10651
10652 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
10653
10654 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
10655
10656 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
10657
10658 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
10659
10660 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10661 MBMessage.class.getName(), _FILTER_COLUMN_PK,
10662 _FILTER_COLUMN_USERID, groupId);
10663
10664 Session session = null;
10665
10666 try {
10667 session = openSession();
10668
10669 SQLQuery q = session.createSQLQuery(sql);
10670
10671 q.addScalar(COUNT_COLUMN_NAME,
10672 com.liferay.portal.kernel.dao.orm.Type.LONG);
10673
10674 QueryPos qPos = QueryPos.getInstance(q);
10675
10676 qPos.add(groupId);
10677
10678 qPos.add(categoryId);
10679
10680 qPos.add(status);
10681
10682 Long count = (Long)q.uniqueResult();
10683
10684 return count.intValue();
10685 }
10686 catch (Exception e) {
10687 throw processException(e);
10688 }
10689 finally {
10690 closeSession(session);
10691 }
10692 }
10693
10694
10703 public int countByC_C_S(long classNameId, long classPK, int status)
10704 throws SystemException {
10705 Object[] finderArgs = new Object[] { classNameId, classPK, status };
10706
10707 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_S,
10708 finderArgs, this);
10709
10710 if (count == null) {
10711 StringBundler query = new StringBundler(4);
10712
10713 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10714
10715 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
10716
10717 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
10718
10719 query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
10720
10721 String sql = query.toString();
10722
10723 Session session = null;
10724
10725 try {
10726 session = openSession();
10727
10728 Query q = session.createQuery(sql);
10729
10730 QueryPos qPos = QueryPos.getInstance(q);
10731
10732 qPos.add(classNameId);
10733
10734 qPos.add(classPK);
10735
10736 qPos.add(status);
10737
10738 count = (Long)q.uniqueResult();
10739 }
10740 catch (Exception e) {
10741 throw processException(e);
10742 }
10743 finally {
10744 if (count == null) {
10745 count = Long.valueOf(0);
10746 }
10747
10748 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_S,
10749 finderArgs, count);
10750
10751 closeSession(session);
10752 }
10753 }
10754
10755 return count.intValue();
10756 }
10757
10758
10768 public int countByG_C_T_S(long groupId, long categoryId, long threadId,
10769 int status) throws SystemException {
10770 Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
10771
10772 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_T_S,
10773 finderArgs, this);
10774
10775 if (count == null) {
10776 StringBundler query = new StringBundler(5);
10777
10778 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10779
10780 query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
10781
10782 query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
10783
10784 query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
10785
10786 query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
10787
10788 String sql = query.toString();
10789
10790 Session session = null;
10791
10792 try {
10793 session = openSession();
10794
10795 Query q = session.createQuery(sql);
10796
10797 QueryPos qPos = QueryPos.getInstance(q);
10798
10799 qPos.add(groupId);
10800
10801 qPos.add(categoryId);
10802
10803 qPos.add(threadId);
10804
10805 qPos.add(status);
10806
10807 count = (Long)q.uniqueResult();
10808 }
10809 catch (Exception e) {
10810 throw processException(e);
10811 }
10812 finally {
10813 if (count == null) {
10814 count = Long.valueOf(0);
10815 }
10816
10817 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_T_S,
10818 finderArgs, count);
10819
10820 closeSession(session);
10821 }
10822 }
10823
10824 return count.intValue();
10825 }
10826
10827
10837 public int filterCountByG_C_T_S(long groupId, long categoryId,
10838 long threadId, int status) throws SystemException {
10839 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10840 return countByG_C_T_S(groupId, categoryId, threadId, status);
10841 }
10842
10843 StringBundler query = new StringBundler(5);
10844
10845 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
10846
10847 query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
10848
10849 query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
10850
10851 query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
10852
10853 query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
10854
10855 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10856 MBMessage.class.getName(), _FILTER_COLUMN_PK,
10857 _FILTER_COLUMN_USERID, groupId);
10858
10859 Session session = null;
10860
10861 try {
10862 session = openSession();
10863
10864 SQLQuery q = session.createSQLQuery(sql);
10865
10866 q.addScalar(COUNT_COLUMN_NAME,
10867 com.liferay.portal.kernel.dao.orm.Type.LONG);
10868
10869 QueryPos qPos = QueryPos.getInstance(q);
10870
10871 qPos.add(groupId);
10872
10873 qPos.add(categoryId);
10874
10875 qPos.add(threadId);
10876
10877 qPos.add(status);
10878
10879 Long count = (Long)q.uniqueResult();
10880
10881 return count.intValue();
10882 }
10883 catch (Exception e) {
10884 throw processException(e);
10885 }
10886 finally {
10887 closeSession(session);
10888 }
10889 }
10890
10891
10897 public int countAll() throws SystemException {
10898 Object[] finderArgs = new Object[0];
10899
10900 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
10901 finderArgs, this);
10902
10903 if (count == null) {
10904 Session session = null;
10905
10906 try {
10907 session = openSession();
10908
10909 Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
10910
10911 count = (Long)q.uniqueResult();
10912 }
10913 catch (Exception e) {
10914 throw processException(e);
10915 }
10916 finally {
10917 if (count == null) {
10918 count = Long.valueOf(0);
10919 }
10920
10921 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
10922 count);
10923
10924 closeSession(session);
10925 }
10926 }
10927
10928 return count.intValue();
10929 }
10930
10931
10934 public void afterPropertiesSet() {
10935 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
10936 com.liferay.portal.util.PropsUtil.get(
10937 "value.object.listener.com.liferay.portlet.messageboards.model.MBMessage")));
10938
10939 if (listenerClassNames.length > 0) {
10940 try {
10941 List<ModelListener<MBMessage>> listenersList = new ArrayList<ModelListener<MBMessage>>();
10942
10943 for (String listenerClassName : listenerClassNames) {
10944 listenersList.add((ModelListener<MBMessage>)InstanceFactory.newInstance(
10945 listenerClassName));
10946 }
10947
10948 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
10949 }
10950 catch (Exception e) {
10951 _log.error(e);
10952 }
10953 }
10954 }
10955
10956 public void destroy() {
10957 EntityCacheUtil.removeCache(MBMessageImpl.class.getName());
10958 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
10959 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
10960 }
10961
10962 @BeanReference(type = MBBanPersistence.class)
10963 protected MBBanPersistence mbBanPersistence;
10964 @BeanReference(type = MBCategoryPersistence.class)
10965 protected MBCategoryPersistence mbCategoryPersistence;
10966 @BeanReference(type = MBDiscussionPersistence.class)
10967 protected MBDiscussionPersistence mbDiscussionPersistence;
10968 @BeanReference(type = MBMailingListPersistence.class)
10969 protected MBMailingListPersistence mbMailingListPersistence;
10970 @BeanReference(type = MBMessagePersistence.class)
10971 protected MBMessagePersistence mbMessagePersistence;
10972 @BeanReference(type = MBMessageFlagPersistence.class)
10973 protected MBMessageFlagPersistence mbMessageFlagPersistence;
10974 @BeanReference(type = MBStatsUserPersistence.class)
10975 protected MBStatsUserPersistence mbStatsUserPersistence;
10976 @BeanReference(type = MBThreadPersistence.class)
10977 protected MBThreadPersistence mbThreadPersistence;
10978 @BeanReference(type = CompanyPersistence.class)
10979 protected CompanyPersistence companyPersistence;
10980 @BeanReference(type = GroupPersistence.class)
10981 protected GroupPersistence groupPersistence;
10982 @BeanReference(type = LockPersistence.class)
10983 protected LockPersistence lockPersistence;
10984 @BeanReference(type = PortletPreferencesPersistence.class)
10985 protected PortletPreferencesPersistence portletPreferencesPersistence;
10986 @BeanReference(type = ResourcePersistence.class)
10987 protected ResourcePersistence resourcePersistence;
10988 @BeanReference(type = SubscriptionPersistence.class)
10989 protected SubscriptionPersistence subscriptionPersistence;
10990 @BeanReference(type = UserPersistence.class)
10991 protected UserPersistence userPersistence;
10992 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
10993 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
10994 @BeanReference(type = AssetEntryPersistence.class)
10995 protected AssetEntryPersistence assetEntryPersistence;
10996 @BeanReference(type = AssetTagPersistence.class)
10997 protected AssetTagPersistence assetTagPersistence;
10998 @BeanReference(type = BlogsEntryPersistence.class)
10999 protected BlogsEntryPersistence blogsEntryPersistence;
11000 @BeanReference(type = ExpandoValuePersistence.class)
11001 protected ExpandoValuePersistence expandoValuePersistence;
11002 @BeanReference(type = RatingsStatsPersistence.class)
11003 protected RatingsStatsPersistence ratingsStatsPersistence;
11004 @BeanReference(type = SocialActivityPersistence.class)
11005 protected SocialActivityPersistence socialActivityPersistence;
11006 @BeanReference(type = SocialEquityLogPersistence.class)
11007 protected SocialEquityLogPersistence socialEquityLogPersistence;
11008 private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
11009 private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
11010 private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
11011 private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
11012 private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
11013 private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
11014 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?)";
11015 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
11016 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
11017 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?) AND ";
11018 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
11019 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ?";
11020 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ?";
11021 private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
11022 private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
11023 private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ?";
11024 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
11025 private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
11026 private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
11027 private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
11028 private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
11029 private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
11030 private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
11031 private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ?";
11032 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
11033 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
11034 private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
11035 private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
11036 private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
11037 private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
11038 private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
11039 private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
11040 private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
11041 private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
11042 private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ?";
11043 private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
11044 private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
11045 private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
11046 private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
11047 private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
11048 private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
11049 private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
11050 private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
11051 private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
11052 private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
11053 private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
11054 private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
11055 private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
11056 private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
11057 private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
11058 "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
11059 private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
11060 ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
11061 private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
11062 private static final String _FILTER_COLUMN_PK = "mbMessage.rootMessageId";
11063 private static final String _FILTER_COLUMN_USERID = "mbMessage.userId";
11064 private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
11065 private static final String _FILTER_ENTITY_TABLE = "MBMessage";
11066 private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
11067 private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
11068 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
11069 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
11070 private static Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
11071 }