1
14
15 package com.liferay.portlet.messageboards.service.persistence;
16
17 import com.liferay.portal.NoSuchModelException;
18 import com.liferay.portal.SystemException;
19 import com.liferay.portal.kernel.annotation.BeanReference;
20 import com.liferay.portal.kernel.cache.CacheRegistry;
21 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23 import com.liferay.portal.kernel.dao.orm.FinderPath;
24 import com.liferay.portal.kernel.dao.orm.Query;
25 import com.liferay.portal.kernel.dao.orm.QueryPos;
26 import com.liferay.portal.kernel.dao.orm.QueryUtil;
27 import com.liferay.portal.kernel.dao.orm.Session;
28 import com.liferay.portal.kernel.log.Log;
29 import com.liferay.portal.kernel.log.LogFactoryUtil;
30 import com.liferay.portal.kernel.util.GetterUtil;
31 import com.liferay.portal.kernel.util.InstanceFactory;
32 import com.liferay.portal.kernel.util.OrderByComparator;
33 import com.liferay.portal.kernel.util.StringBundler;
34 import com.liferay.portal.kernel.util.StringPool;
35 import com.liferay.portal.kernel.util.StringUtil;
36 import com.liferay.portal.kernel.util.Validator;
37 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
38 import com.liferay.portal.model.ModelListener;
39 import com.liferay.portal.service.persistence.BatchSessionUtil;
40 import com.liferay.portal.service.persistence.CompanyPersistence;
41 import com.liferay.portal.service.persistence.GroupPersistence;
42 import com.liferay.portal.service.persistence.LockPersistence;
43 import com.liferay.portal.service.persistence.PortletPreferencesPersistence;
44 import com.liferay.portal.service.persistence.ResourcePersistence;
45 import com.liferay.portal.service.persistence.SubscriptionPersistence;
46 import com.liferay.portal.service.persistence.UserPersistence;
47 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
48
49 import com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence;
50 import com.liferay.portlet.messageboards.NoSuchMessageException;
51 import com.liferay.portlet.messageboards.model.MBMessage;
52 import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
53 import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
54 import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
55 import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
56 import com.liferay.portlet.tags.service.persistence.TagsAssetPersistence;
57 import com.liferay.portlet.tags.service.persistence.TagsEntryPersistence;
58
59 import java.io.Serializable;
60
61 import java.util.ArrayList;
62 import java.util.Collections;
63 import java.util.List;
64
65
78 public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
79 implements MBMessagePersistence {
80 public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
81 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
82 ".List";
83 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
84 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
85 "findByUuid",
86 new String[] {
87 String.class.getName(),
88
89 "java.lang.Integer", "java.lang.Integer",
90 "com.liferay.portal.kernel.util.OrderByComparator"
91 });
92 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
93 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
94 "countByUuid", new String[] { String.class.getName() });
95 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
96 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
97 "fetchByUUID_G",
98 new String[] { String.class.getName(), Long.class.getName() });
99 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
100 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
101 "countByUUID_G",
102 new String[] { String.class.getName(), Long.class.getName() });
103 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
104 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
105 "findByCompanyId",
106 new String[] {
107 Long.class.getName(),
108
109 "java.lang.Integer", "java.lang.Integer",
110 "com.liferay.portal.kernel.util.OrderByComparator"
111 });
112 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
113 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
114 "countByCompanyId", new String[] { Long.class.getName() });
115 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
116 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
117 "findByGroupId",
118 new String[] {
119 Long.class.getName(),
120
121 "java.lang.Integer", "java.lang.Integer",
122 "com.liferay.portal.kernel.util.OrderByComparator"
123 });
124 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
125 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
126 "countByGroupId", new String[] { Long.class.getName() });
127 public static final FinderPath FINDER_PATH_FIND_BY_CATEGORYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
128 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
129 "findByCategoryId",
130 new String[] {
131 Long.class.getName(),
132
133 "java.lang.Integer", "java.lang.Integer",
134 "com.liferay.portal.kernel.util.OrderByComparator"
135 });
136 public static final FinderPath FINDER_PATH_COUNT_BY_CATEGORYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
137 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
138 "countByCategoryId", new String[] { Long.class.getName() });
139 public static final FinderPath FINDER_PATH_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
140 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
141 "findByThreadId",
142 new String[] {
143 Long.class.getName(),
144
145 "java.lang.Integer", "java.lang.Integer",
146 "com.liferay.portal.kernel.util.OrderByComparator"
147 });
148 public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
149 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
150 "countByThreadId", new String[] { Long.class.getName() });
151 public static final FinderPath FINDER_PATH_FIND_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
152 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
153 "findByThreadReplies",
154 new String[] {
155 Long.class.getName(),
156
157 "java.lang.Integer", "java.lang.Integer",
158 "com.liferay.portal.kernel.util.OrderByComparator"
159 });
160 public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
161 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
162 "countByThreadReplies", new String[] { Long.class.getName() });
163 public static final FinderPath FINDER_PATH_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
164 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
165 "findByG_U",
166 new String[] {
167 Long.class.getName(), Long.class.getName(),
168
169 "java.lang.Integer", "java.lang.Integer",
170 "com.liferay.portal.kernel.util.OrderByComparator"
171 });
172 public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
173 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
174 "countByG_U",
175 new String[] { Long.class.getName(), Long.class.getName() });
176 public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
177 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
178 "findByC_C",
179 new String[] {
180 Long.class.getName(), Long.class.getName(),
181
182 "java.lang.Integer", "java.lang.Integer",
183 "com.liferay.portal.kernel.util.OrderByComparator"
184 });
185 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
186 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
187 "countByC_C",
188 new String[] { Long.class.getName(), Long.class.getName() });
189 public static final FinderPath FINDER_PATH_FIND_BY_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
190 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
191 "findByC_T",
192 new String[] {
193 Long.class.getName(), Long.class.getName(),
194
195 "java.lang.Integer", "java.lang.Integer",
196 "com.liferay.portal.kernel.util.OrderByComparator"
197 });
198 public static final FinderPath FINDER_PATH_COUNT_BY_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
199 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
200 "countByC_T",
201 new String[] { Long.class.getName(), Long.class.getName() });
202 public static final FinderPath FINDER_PATH_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
203 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
204 "findByT_P",
205 new String[] {
206 Long.class.getName(), Long.class.getName(),
207
208 "java.lang.Integer", "java.lang.Integer",
209 "com.liferay.portal.kernel.util.OrderByComparator"
210 });
211 public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
212 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
213 "countByT_P",
214 new String[] { Long.class.getName(), Long.class.getName() });
215 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
216 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
217 "findAll", new String[0]);
218 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
219 MBMessageModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
220 "countAll", new String[0]);
221
222 public void cacheResult(MBMessage mbMessage) {
223 EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
224 MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
225
226 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
227 new Object[] { mbMessage.getUuid(), new Long(mbMessage.getGroupId()) },
228 mbMessage);
229 }
230
231 public void cacheResult(List<MBMessage> mbMessages) {
232 for (MBMessage mbMessage : mbMessages) {
233 if (EntityCacheUtil.getResult(
234 MBMessageModelImpl.ENTITY_CACHE_ENABLED,
235 MBMessageImpl.class, mbMessage.getPrimaryKey(), this) == null) {
236 cacheResult(mbMessage);
237 }
238 }
239 }
240
241 public void clearCache() {
242 CacheRegistry.clear(MBMessageImpl.class.getName());
243 EntityCacheUtil.clearCache(MBMessageImpl.class.getName());
244 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
245 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
246 }
247
248 public void clearCache(MBMessage mbMessage) {
249 EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
250 MBMessageImpl.class, mbMessage.getPrimaryKey());
251
252 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
253 new Object[] { mbMessage.getUuid(), new Long(mbMessage.getGroupId()) });
254 }
255
256 public MBMessage create(long messageId) {
257 MBMessage mbMessage = new MBMessageImpl();
258
259 mbMessage.setNew(true);
260 mbMessage.setPrimaryKey(messageId);
261
262 String uuid = PortalUUIDUtil.generate();
263
264 mbMessage.setUuid(uuid);
265
266 return mbMessage;
267 }
268
269 public MBMessage remove(Serializable primaryKey)
270 throws NoSuchModelException, SystemException {
271 return remove(((Long)primaryKey).longValue());
272 }
273
274 public MBMessage remove(long messageId)
275 throws NoSuchMessageException, SystemException {
276 Session session = null;
277
278 try {
279 session = openSession();
280
281 MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
282 new Long(messageId));
283
284 if (mbMessage == null) {
285 if (_log.isWarnEnabled()) {
286 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageId);
287 }
288
289 throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
290 messageId);
291 }
292
293 return remove(mbMessage);
294 }
295 catch (NoSuchMessageException nsee) {
296 throw nsee;
297 }
298 catch (Exception e) {
299 throw processException(e);
300 }
301 finally {
302 closeSession(session);
303 }
304 }
305
306 protected MBMessage removeImpl(MBMessage mbMessage)
307 throws SystemException {
308 mbMessage = toUnwrappedModel(mbMessage);
309
310 Session session = null;
311
312 try {
313 session = openSession();
314
315 BatchSessionUtil.delete(session, mbMessage);
316 }
317 catch (Exception e) {
318 throw processException(e);
319 }
320 finally {
321 closeSession(session);
322 }
323
324 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
325
326 MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
327
328 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
329 new Object[] {
330 mbMessageModelImpl.getOriginalUuid(),
331 new Long(mbMessageModelImpl.getOriginalGroupId())
332 });
333
334 EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
335 MBMessageImpl.class, mbMessage.getPrimaryKey());
336
337 return mbMessage;
338 }
339
340
343 public MBMessage update(MBMessage mbMessage) throws SystemException {
344 if (_log.isWarnEnabled()) {
345 _log.warn(
346 "Using the deprecated update(MBMessage mbMessage) method. Use update(MBMessage mbMessage, boolean merge) instead.");
347 }
348
349 return update(mbMessage, false);
350 }
351
352 public MBMessage updateImpl(
353 com.liferay.portlet.messageboards.model.MBMessage mbMessage,
354 boolean merge) throws SystemException {
355 mbMessage = toUnwrappedModel(mbMessage);
356
357 boolean isNew = mbMessage.isNew();
358
359 MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
360
361 if (Validator.isNull(mbMessage.getUuid())) {
362 String uuid = PortalUUIDUtil.generate();
363
364 mbMessage.setUuid(uuid);
365 }
366
367 Session session = null;
368
369 try {
370 session = openSession();
371
372 BatchSessionUtil.update(session, mbMessage, merge);
373
374 mbMessage.setNew(false);
375 }
376 catch (Exception e) {
377 throw processException(e);
378 }
379 finally {
380 closeSession(session);
381 }
382
383 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
384
385 EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
386 MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
387
388 if (!isNew &&
389 (!Validator.equals(mbMessage.getUuid(),
390 mbMessageModelImpl.getOriginalUuid()) ||
391 (mbMessage.getGroupId() != mbMessageModelImpl.getOriginalGroupId()))) {
392 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
393 new Object[] {
394 mbMessageModelImpl.getOriginalUuid(),
395 new Long(mbMessageModelImpl.getOriginalGroupId())
396 });
397 }
398
399 if (isNew ||
400 (!Validator.equals(mbMessage.getUuid(),
401 mbMessageModelImpl.getOriginalUuid()) ||
402 (mbMessage.getGroupId() != mbMessageModelImpl.getOriginalGroupId()))) {
403 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
404 new Object[] {
405 mbMessage.getUuid(), new Long(mbMessage.getGroupId())
406 }, mbMessage);
407 }
408
409 return mbMessage;
410 }
411
412 protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
413 if (mbMessage instanceof MBMessageImpl) {
414 return mbMessage;
415 }
416
417 MBMessageImpl mbMessageImpl = new MBMessageImpl();
418
419 mbMessageImpl.setNew(mbMessage.isNew());
420 mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
421
422 mbMessageImpl.setUuid(mbMessage.getUuid());
423 mbMessageImpl.setMessageId(mbMessage.getMessageId());
424 mbMessageImpl.setGroupId(mbMessage.getGroupId());
425 mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
426 mbMessageImpl.setUserId(mbMessage.getUserId());
427 mbMessageImpl.setUserName(mbMessage.getUserName());
428 mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
429 mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
430 mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
431 mbMessageImpl.setClassPK(mbMessage.getClassPK());
432 mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
433 mbMessageImpl.setThreadId(mbMessage.getThreadId());
434 mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
435 mbMessageImpl.setSubject(mbMessage.getSubject());
436 mbMessageImpl.setBody(mbMessage.getBody());
437 mbMessageImpl.setAttachments(mbMessage.isAttachments());
438 mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
439 mbMessageImpl.setPriority(mbMessage.getPriority());
440
441 return mbMessageImpl;
442 }
443
444 public MBMessage findByPrimaryKey(Serializable primaryKey)
445 throws NoSuchModelException, SystemException {
446 return findByPrimaryKey(((Long)primaryKey).longValue());
447 }
448
449 public MBMessage findByPrimaryKey(long messageId)
450 throws NoSuchMessageException, SystemException {
451 MBMessage mbMessage = fetchByPrimaryKey(messageId);
452
453 if (mbMessage == null) {
454 if (_log.isWarnEnabled()) {
455 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageId);
456 }
457
458 throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
459 messageId);
460 }
461
462 return mbMessage;
463 }
464
465 public MBMessage fetchByPrimaryKey(Serializable primaryKey)
466 throws SystemException {
467 return fetchByPrimaryKey(((Long)primaryKey).longValue());
468 }
469
470 public MBMessage fetchByPrimaryKey(long messageId)
471 throws SystemException {
472 MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
473 MBMessageImpl.class, messageId, this);
474
475 if (mbMessage == null) {
476 Session session = null;
477
478 try {
479 session = openSession();
480
481 mbMessage = (MBMessage)session.get(MBMessageImpl.class,
482 new Long(messageId));
483 }
484 catch (Exception e) {
485 throw processException(e);
486 }
487 finally {
488 if (mbMessage != null) {
489 cacheResult(mbMessage);
490 }
491
492 closeSession(session);
493 }
494 }
495
496 return mbMessage;
497 }
498
499 public List<MBMessage> findByUuid(String uuid) throws SystemException {
500 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
501 }
502
503 public List<MBMessage> findByUuid(String uuid, int start, int end)
504 throws SystemException {
505 return findByUuid(uuid, start, end, null);
506 }
507
508 public List<MBMessage> findByUuid(String uuid, int start, int end,
509 OrderByComparator orderByComparator) throws SystemException {
510 Object[] finderArgs = new Object[] {
511 uuid,
512
513 String.valueOf(start), String.valueOf(end),
514 String.valueOf(orderByComparator)
515 };
516
517 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
518 finderArgs, this);
519
520 if (list == null) {
521 StringBundler query = null;
522
523 if (orderByComparator != null) {
524 query = new StringBundler(3 +
525 (orderByComparator.getOrderByFields().length * 3));
526 }
527 else {
528 query = new StringBundler(3);
529 }
530
531 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
532
533 if (uuid == null) {
534 query.append(_FINDER_COLUMN_UUID_UUID_1);
535 }
536 else {
537 if (uuid.equals(StringPool.BLANK)) {
538 query.append(_FINDER_COLUMN_UUID_UUID_3);
539 }
540 else {
541 query.append(_FINDER_COLUMN_UUID_UUID_2);
542 }
543 }
544
545 if (orderByComparator != null) {
546 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
547 orderByComparator);
548 }
549
550 else {
551 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
552 }
553
554 String sql = query.toString();
555
556 Session session = null;
557
558 try {
559 session = openSession();
560
561 Query q = session.createQuery(sql);
562
563 QueryPos qPos = QueryPos.getInstance(q);
564
565 if (uuid != null) {
566 qPos.add(uuid);
567 }
568
569 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
570 end);
571 }
572 catch (Exception e) {
573 throw processException(e);
574 }
575 finally {
576 if (list == null) {
577 list = new ArrayList<MBMessage>();
578 }
579
580 cacheResult(list);
581
582 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
583 list);
584
585 closeSession(session);
586 }
587 }
588
589 return list;
590 }
591
592 public MBMessage findByUuid_First(String uuid,
593 OrderByComparator orderByComparator)
594 throws NoSuchMessageException, SystemException {
595 List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
596
597 if (list.isEmpty()) {
598 StringBundler msg = new StringBundler(4);
599
600 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
601
602 msg.append("uuid=");
603 msg.append(uuid);
604
605 msg.append(StringPool.CLOSE_CURLY_BRACE);
606
607 throw new NoSuchMessageException(msg.toString());
608 }
609 else {
610 return list.get(0);
611 }
612 }
613
614 public MBMessage findByUuid_Last(String uuid,
615 OrderByComparator orderByComparator)
616 throws NoSuchMessageException, SystemException {
617 int count = countByUuid(uuid);
618
619 List<MBMessage> list = findByUuid(uuid, count - 1, count,
620 orderByComparator);
621
622 if (list.isEmpty()) {
623 StringBundler msg = new StringBundler(4);
624
625 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
626
627 msg.append("uuid=");
628 msg.append(uuid);
629
630 msg.append(StringPool.CLOSE_CURLY_BRACE);
631
632 throw new NoSuchMessageException(msg.toString());
633 }
634 else {
635 return list.get(0);
636 }
637 }
638
639 public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
640 OrderByComparator orderByComparator)
641 throws NoSuchMessageException, SystemException {
642 MBMessage mbMessage = findByPrimaryKey(messageId);
643
644 Session session = null;
645
646 try {
647 session = openSession();
648
649 MBMessage[] array = new MBMessageImpl[3];
650
651 array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
652 orderByComparator, true);
653
654 array[1] = mbMessage;
655
656 array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
657 orderByComparator, false);
658
659 return array;
660 }
661 catch (Exception e) {
662 throw processException(e);
663 }
664 finally {
665 closeSession(session);
666 }
667 }
668
669 protected MBMessage getByUuid_PrevAndNext(Session session,
670 MBMessage mbMessage, String uuid, OrderByComparator orderByComparator,
671 boolean previous) {
672 StringBundler query = null;
673
674 if (orderByComparator != null) {
675 query = new StringBundler(6 +
676 (orderByComparator.getOrderByFields().length * 6));
677 }
678 else {
679 query = new StringBundler(3);
680 }
681
682 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
683
684 if (uuid == null) {
685 query.append(_FINDER_COLUMN_UUID_UUID_1);
686 }
687 else {
688 if (uuid.equals(StringPool.BLANK)) {
689 query.append(_FINDER_COLUMN_UUID_UUID_3);
690 }
691 else {
692 query.append(_FINDER_COLUMN_UUID_UUID_2);
693 }
694 }
695
696 if (orderByComparator != null) {
697 String[] orderByFields = orderByComparator.getOrderByFields();
698
699 if (orderByFields.length > 0) {
700 query.append(WHERE_AND);
701 }
702
703 for (int i = 0; i < orderByFields.length; i++) {
704 query.append(_ORDER_BY_ENTITY_ALIAS);
705 query.append(orderByFields[i]);
706
707 if ((i + 1) < orderByFields.length) {
708 if (orderByComparator.isAscending() ^ previous) {
709 query.append(WHERE_GREATER_THAN_HAS_NEXT);
710 }
711 else {
712 query.append(WHERE_LESSER_THAN_HAS_NEXT);
713 }
714 }
715 else {
716 if (orderByComparator.isAscending() ^ previous) {
717 query.append(WHERE_GREATER_THAN);
718 }
719 else {
720 query.append(WHERE_LESSER_THAN);
721 }
722 }
723 }
724
725 query.append(ORDER_BY_CLAUSE);
726
727 for (int i = 0; i < orderByFields.length; i++) {
728 query.append(_ORDER_BY_ENTITY_ALIAS);
729 query.append(orderByFields[i]);
730
731 if ((i + 1) < orderByFields.length) {
732 if (orderByComparator.isAscending() ^ previous) {
733 query.append(ORDER_BY_ASC_HAS_NEXT);
734 }
735 else {
736 query.append(ORDER_BY_DESC_HAS_NEXT);
737 }
738 }
739 else {
740 if (orderByComparator.isAscending() ^ previous) {
741 query.append(ORDER_BY_ASC);
742 }
743 else {
744 query.append(ORDER_BY_DESC);
745 }
746 }
747 }
748 }
749
750 else {
751 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
752 }
753
754 String sql = query.toString();
755
756 Query q = session.createQuery(sql);
757
758 q.setFirstResult(0);
759 q.setMaxResults(2);
760
761 QueryPos qPos = QueryPos.getInstance(q);
762
763 if (uuid != null) {
764 qPos.add(uuid);
765 }
766
767 if (orderByComparator != null) {
768 Object[] values = orderByComparator.getOrderByValues(mbMessage);
769
770 for (Object value : values) {
771 qPos.add(value);
772 }
773 }
774
775 List<MBMessage> list = q.list();
776
777 if (list.size() == 2) {
778 return list.get(1);
779 }
780 else {
781 return null;
782 }
783 }
784
785 public MBMessage findByUUID_G(String uuid, long groupId)
786 throws NoSuchMessageException, SystemException {
787 MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
788
789 if (mbMessage == null) {
790 StringBundler msg = new StringBundler(6);
791
792 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
793
794 msg.append("uuid=");
795 msg.append(uuid);
796
797 msg.append(", groupId=");
798 msg.append(groupId);
799
800 msg.append(StringPool.CLOSE_CURLY_BRACE);
801
802 if (_log.isWarnEnabled()) {
803 _log.warn(msg.toString());
804 }
805
806 throw new NoSuchMessageException(msg.toString());
807 }
808
809 return mbMessage;
810 }
811
812 public MBMessage fetchByUUID_G(String uuid, long groupId)
813 throws SystemException {
814 return fetchByUUID_G(uuid, groupId, true);
815 }
816
817 public MBMessage fetchByUUID_G(String uuid, long groupId,
818 boolean retrieveFromCache) throws SystemException {
819 Object[] finderArgs = new Object[] { uuid, groupId };
820
821 Object result = null;
822
823 if (retrieveFromCache) {
824 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
825 finderArgs, this);
826 }
827
828 if (result == null) {
829 StringBundler query = new StringBundler(4);
830
831 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
832
833 if (uuid == null) {
834 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
835 }
836 else {
837 if (uuid.equals(StringPool.BLANK)) {
838 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
839 }
840 else {
841 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
842 }
843 }
844
845 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
846
847 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
848
849 String sql = query.toString();
850
851 Session session = null;
852
853 try {
854 session = openSession();
855
856 Query q = session.createQuery(sql);
857
858 QueryPos qPos = QueryPos.getInstance(q);
859
860 if (uuid != null) {
861 qPos.add(uuid);
862 }
863
864 qPos.add(groupId);
865
866 List<MBMessage> list = q.list();
867
868 result = list;
869
870 MBMessage mbMessage = null;
871
872 if (list.isEmpty()) {
873 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
874 finderArgs, list);
875 }
876 else {
877 mbMessage = list.get(0);
878
879 cacheResult(mbMessage);
880
881 if ((mbMessage.getUuid() == null) ||
882 !mbMessage.getUuid().equals(uuid) ||
883 (mbMessage.getGroupId() != groupId)) {
884 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
885 finderArgs, mbMessage);
886 }
887 }
888
889 return mbMessage;
890 }
891 catch (Exception e) {
892 throw processException(e);
893 }
894 finally {
895 if (result == null) {
896 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
897 finderArgs, new ArrayList<MBMessage>());
898 }
899
900 closeSession(session);
901 }
902 }
903 else {
904 if (result instanceof List<?>) {
905 return null;
906 }
907 else {
908 return (MBMessage)result;
909 }
910 }
911 }
912
913 public List<MBMessage> findByCompanyId(long companyId)
914 throws SystemException {
915 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
916 null);
917 }
918
919 public List<MBMessage> findByCompanyId(long companyId, int start, int end)
920 throws SystemException {
921 return findByCompanyId(companyId, start, end, null);
922 }
923
924 public List<MBMessage> findByCompanyId(long companyId, int start, int end,
925 OrderByComparator orderByComparator) throws SystemException {
926 Object[] finderArgs = new Object[] {
927 companyId,
928
929 String.valueOf(start), String.valueOf(end),
930 String.valueOf(orderByComparator)
931 };
932
933 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
934 finderArgs, this);
935
936 if (list == null) {
937 StringBundler query = null;
938
939 if (orderByComparator != null) {
940 query = new StringBundler(3 +
941 (orderByComparator.getOrderByFields().length * 3));
942 }
943 else {
944 query = new StringBundler(3);
945 }
946
947 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
948
949 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
950
951 if (orderByComparator != null) {
952 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
953 orderByComparator);
954 }
955
956 else {
957 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
958 }
959
960 String sql = query.toString();
961
962 Session session = null;
963
964 try {
965 session = openSession();
966
967 Query q = session.createQuery(sql);
968
969 QueryPos qPos = QueryPos.getInstance(q);
970
971 qPos.add(companyId);
972
973 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
974 end);
975 }
976 catch (Exception e) {
977 throw processException(e);
978 }
979 finally {
980 if (list == null) {
981 list = new ArrayList<MBMessage>();
982 }
983
984 cacheResult(list);
985
986 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
987 finderArgs, list);
988
989 closeSession(session);
990 }
991 }
992
993 return list;
994 }
995
996 public MBMessage findByCompanyId_First(long companyId,
997 OrderByComparator orderByComparator)
998 throws NoSuchMessageException, SystemException {
999 List<MBMessage> list = findByCompanyId(companyId, 0, 1,
1000 orderByComparator);
1001
1002 if (list.isEmpty()) {
1003 StringBundler msg = new StringBundler(4);
1004
1005 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1006
1007 msg.append("companyId=");
1008 msg.append(companyId);
1009
1010 msg.append(StringPool.CLOSE_CURLY_BRACE);
1011
1012 throw new NoSuchMessageException(msg.toString());
1013 }
1014 else {
1015 return list.get(0);
1016 }
1017 }
1018
1019 public MBMessage findByCompanyId_Last(long companyId,
1020 OrderByComparator orderByComparator)
1021 throws NoSuchMessageException, SystemException {
1022 int count = countByCompanyId(companyId);
1023
1024 List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
1025 orderByComparator);
1026
1027 if (list.isEmpty()) {
1028 StringBundler msg = new StringBundler(4);
1029
1030 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1031
1032 msg.append("companyId=");
1033 msg.append(companyId);
1034
1035 msg.append(StringPool.CLOSE_CURLY_BRACE);
1036
1037 throw new NoSuchMessageException(msg.toString());
1038 }
1039 else {
1040 return list.get(0);
1041 }
1042 }
1043
1044 public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
1045 long companyId, OrderByComparator orderByComparator)
1046 throws NoSuchMessageException, SystemException {
1047 MBMessage mbMessage = findByPrimaryKey(messageId);
1048
1049 Session session = null;
1050
1051 try {
1052 session = openSession();
1053
1054 MBMessage[] array = new MBMessageImpl[3];
1055
1056 array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
1057 companyId, orderByComparator, true);
1058
1059 array[1] = mbMessage;
1060
1061 array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
1062 companyId, orderByComparator, false);
1063
1064 return array;
1065 }
1066 catch (Exception e) {
1067 throw processException(e);
1068 }
1069 finally {
1070 closeSession(session);
1071 }
1072 }
1073
1074 protected MBMessage getByCompanyId_PrevAndNext(Session session,
1075 MBMessage mbMessage, long companyId,
1076 OrderByComparator orderByComparator, boolean previous) {
1077 StringBundler query = null;
1078
1079 if (orderByComparator != null) {
1080 query = new StringBundler(6 +
1081 (orderByComparator.getOrderByFields().length * 6));
1082 }
1083 else {
1084 query = new StringBundler(3);
1085 }
1086
1087 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1088
1089 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1090
1091 if (orderByComparator != null) {
1092 String[] orderByFields = orderByComparator.getOrderByFields();
1093
1094 if (orderByFields.length > 0) {
1095 query.append(WHERE_AND);
1096 }
1097
1098 for (int i = 0; i < orderByFields.length; i++) {
1099 query.append(_ORDER_BY_ENTITY_ALIAS);
1100 query.append(orderByFields[i]);
1101
1102 if ((i + 1) < orderByFields.length) {
1103 if (orderByComparator.isAscending() ^ previous) {
1104 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1105 }
1106 else {
1107 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1108 }
1109 }
1110 else {
1111 if (orderByComparator.isAscending() ^ previous) {
1112 query.append(WHERE_GREATER_THAN);
1113 }
1114 else {
1115 query.append(WHERE_LESSER_THAN);
1116 }
1117 }
1118 }
1119
1120 query.append(ORDER_BY_CLAUSE);
1121
1122 for (int i = 0; i < orderByFields.length; i++) {
1123 query.append(_ORDER_BY_ENTITY_ALIAS);
1124 query.append(orderByFields[i]);
1125
1126 if ((i + 1) < orderByFields.length) {
1127 if (orderByComparator.isAscending() ^ previous) {
1128 query.append(ORDER_BY_ASC_HAS_NEXT);
1129 }
1130 else {
1131 query.append(ORDER_BY_DESC_HAS_NEXT);
1132 }
1133 }
1134 else {
1135 if (orderByComparator.isAscending() ^ previous) {
1136 query.append(ORDER_BY_ASC);
1137 }
1138 else {
1139 query.append(ORDER_BY_DESC);
1140 }
1141 }
1142 }
1143 }
1144
1145 else {
1146 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1147 }
1148
1149 String sql = query.toString();
1150
1151 Query q = session.createQuery(sql);
1152
1153 q.setFirstResult(0);
1154 q.setMaxResults(2);
1155
1156 QueryPos qPos = QueryPos.getInstance(q);
1157
1158 qPos.add(companyId);
1159
1160 if (orderByComparator != null) {
1161 Object[] values = orderByComparator.getOrderByValues(mbMessage);
1162
1163 for (Object value : values) {
1164 qPos.add(value);
1165 }
1166 }
1167
1168 List<MBMessage> list = q.list();
1169
1170 if (list.size() == 2) {
1171 return list.get(1);
1172 }
1173 else {
1174 return null;
1175 }
1176 }
1177
1178 public List<MBMessage> findByGroupId(long groupId)
1179 throws SystemException {
1180 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1181 }
1182
1183 public List<MBMessage> findByGroupId(long groupId, int start, int end)
1184 throws SystemException {
1185 return findByGroupId(groupId, start, end, null);
1186 }
1187
1188 public List<MBMessage> findByGroupId(long groupId, int start, int end,
1189 OrderByComparator orderByComparator) throws SystemException {
1190 Object[] finderArgs = new Object[] {
1191 groupId,
1192
1193 String.valueOf(start), String.valueOf(end),
1194 String.valueOf(orderByComparator)
1195 };
1196
1197 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1198 finderArgs, this);
1199
1200 if (list == null) {
1201 StringBundler query = null;
1202
1203 if (orderByComparator != null) {
1204 query = new StringBundler(3 +
1205 (orderByComparator.getOrderByFields().length * 3));
1206 }
1207 else {
1208 query = new StringBundler(3);
1209 }
1210
1211 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1212
1213 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1214
1215 if (orderByComparator != null) {
1216 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1217 orderByComparator);
1218 }
1219
1220 else {
1221 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1222 }
1223
1224 String sql = query.toString();
1225
1226 Session session = null;
1227
1228 try {
1229 session = openSession();
1230
1231 Query q = session.createQuery(sql);
1232
1233 QueryPos qPos = QueryPos.getInstance(q);
1234
1235 qPos.add(groupId);
1236
1237 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
1238 end);
1239 }
1240 catch (Exception e) {
1241 throw processException(e);
1242 }
1243 finally {
1244 if (list == null) {
1245 list = new ArrayList<MBMessage>();
1246 }
1247
1248 cacheResult(list);
1249
1250 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1251 finderArgs, list);
1252
1253 closeSession(session);
1254 }
1255 }
1256
1257 return list;
1258 }
1259
1260 public MBMessage findByGroupId_First(long groupId,
1261 OrderByComparator orderByComparator)
1262 throws NoSuchMessageException, SystemException {
1263 List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1264
1265 if (list.isEmpty()) {
1266 StringBundler msg = new StringBundler(4);
1267
1268 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1269
1270 msg.append("groupId=");
1271 msg.append(groupId);
1272
1273 msg.append(StringPool.CLOSE_CURLY_BRACE);
1274
1275 throw new NoSuchMessageException(msg.toString());
1276 }
1277 else {
1278 return list.get(0);
1279 }
1280 }
1281
1282 public MBMessage findByGroupId_Last(long groupId,
1283 OrderByComparator orderByComparator)
1284 throws NoSuchMessageException, SystemException {
1285 int count = countByGroupId(groupId);
1286
1287 List<MBMessage> list = findByGroupId(groupId, count - 1, count,
1288 orderByComparator);
1289
1290 if (list.isEmpty()) {
1291 StringBundler msg = new StringBundler(4);
1292
1293 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1294
1295 msg.append("groupId=");
1296 msg.append(groupId);
1297
1298 msg.append(StringPool.CLOSE_CURLY_BRACE);
1299
1300 throw new NoSuchMessageException(msg.toString());
1301 }
1302 else {
1303 return list.get(0);
1304 }
1305 }
1306
1307 public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
1308 OrderByComparator orderByComparator)
1309 throws NoSuchMessageException, SystemException {
1310 MBMessage mbMessage = findByPrimaryKey(messageId);
1311
1312 Session session = null;
1313
1314 try {
1315 session = openSession();
1316
1317 MBMessage[] array = new MBMessageImpl[3];
1318
1319 array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1320 orderByComparator, true);
1321
1322 array[1] = mbMessage;
1323
1324 array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1325 orderByComparator, false);
1326
1327 return array;
1328 }
1329 catch (Exception e) {
1330 throw processException(e);
1331 }
1332 finally {
1333 closeSession(session);
1334 }
1335 }
1336
1337 protected MBMessage getByGroupId_PrevAndNext(Session session,
1338 MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
1339 boolean previous) {
1340 StringBundler query = null;
1341
1342 if (orderByComparator != null) {
1343 query = new StringBundler(6 +
1344 (orderByComparator.getOrderByFields().length * 6));
1345 }
1346 else {
1347 query = new StringBundler(3);
1348 }
1349
1350 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1351
1352 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1353
1354 if (orderByComparator != null) {
1355 String[] orderByFields = orderByComparator.getOrderByFields();
1356
1357 if (orderByFields.length > 0) {
1358 query.append(WHERE_AND);
1359 }
1360
1361 for (int i = 0; i < orderByFields.length; i++) {
1362 query.append(_ORDER_BY_ENTITY_ALIAS);
1363 query.append(orderByFields[i]);
1364
1365 if ((i + 1) < orderByFields.length) {
1366 if (orderByComparator.isAscending() ^ previous) {
1367 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1368 }
1369 else {
1370 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1371 }
1372 }
1373 else {
1374 if (orderByComparator.isAscending() ^ previous) {
1375 query.append(WHERE_GREATER_THAN);
1376 }
1377 else {
1378 query.append(WHERE_LESSER_THAN);
1379 }
1380 }
1381 }
1382
1383 query.append(ORDER_BY_CLAUSE);
1384
1385 for (int i = 0; i < orderByFields.length; i++) {
1386 query.append(_ORDER_BY_ENTITY_ALIAS);
1387 query.append(orderByFields[i]);
1388
1389 if ((i + 1) < orderByFields.length) {
1390 if (orderByComparator.isAscending() ^ previous) {
1391 query.append(ORDER_BY_ASC_HAS_NEXT);
1392 }
1393 else {
1394 query.append(ORDER_BY_DESC_HAS_NEXT);
1395 }
1396 }
1397 else {
1398 if (orderByComparator.isAscending() ^ previous) {
1399 query.append(ORDER_BY_ASC);
1400 }
1401 else {
1402 query.append(ORDER_BY_DESC);
1403 }
1404 }
1405 }
1406 }
1407
1408 else {
1409 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1410 }
1411
1412 String sql = query.toString();
1413
1414 Query q = session.createQuery(sql);
1415
1416 q.setFirstResult(0);
1417 q.setMaxResults(2);
1418
1419 QueryPos qPos = QueryPos.getInstance(q);
1420
1421 qPos.add(groupId);
1422
1423 if (orderByComparator != null) {
1424 Object[] values = orderByComparator.getOrderByValues(mbMessage);
1425
1426 for (Object value : values) {
1427 qPos.add(value);
1428 }
1429 }
1430
1431 List<MBMessage> list = q.list();
1432
1433 if (list.size() == 2) {
1434 return list.get(1);
1435 }
1436 else {
1437 return null;
1438 }
1439 }
1440
1441 public List<MBMessage> findByCategoryId(long categoryId)
1442 throws SystemException {
1443 return findByCategoryId(categoryId, QueryUtil.ALL_POS,
1444 QueryUtil.ALL_POS, null);
1445 }
1446
1447 public List<MBMessage> findByCategoryId(long categoryId, int start, int end)
1448 throws SystemException {
1449 return findByCategoryId(categoryId, start, end, null);
1450 }
1451
1452 public List<MBMessage> findByCategoryId(long categoryId, int start,
1453 int end, OrderByComparator orderByComparator) throws SystemException {
1454 Object[] finderArgs = new Object[] {
1455 categoryId,
1456
1457 String.valueOf(start), String.valueOf(end),
1458 String.valueOf(orderByComparator)
1459 };
1460
1461 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_CATEGORYID,
1462 finderArgs, this);
1463
1464 if (list == null) {
1465 StringBundler query = null;
1466
1467 if (orderByComparator != null) {
1468 query = new StringBundler(3 +
1469 (orderByComparator.getOrderByFields().length * 3));
1470 }
1471 else {
1472 query = new StringBundler(3);
1473 }
1474
1475 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1476
1477 query.append(_FINDER_COLUMN_CATEGORYID_CATEGORYID_2);
1478
1479 if (orderByComparator != null) {
1480 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1481 orderByComparator);
1482 }
1483
1484 else {
1485 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1486 }
1487
1488 String sql = query.toString();
1489
1490 Session session = null;
1491
1492 try {
1493 session = openSession();
1494
1495 Query q = session.createQuery(sql);
1496
1497 QueryPos qPos = QueryPos.getInstance(q);
1498
1499 qPos.add(categoryId);
1500
1501 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
1502 end);
1503 }
1504 catch (Exception e) {
1505 throw processException(e);
1506 }
1507 finally {
1508 if (list == null) {
1509 list = new ArrayList<MBMessage>();
1510 }
1511
1512 cacheResult(list);
1513
1514 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_CATEGORYID,
1515 finderArgs, list);
1516
1517 closeSession(session);
1518 }
1519 }
1520
1521 return list;
1522 }
1523
1524 public MBMessage findByCategoryId_First(long categoryId,
1525 OrderByComparator orderByComparator)
1526 throws NoSuchMessageException, SystemException {
1527 List<MBMessage> list = findByCategoryId(categoryId, 0, 1,
1528 orderByComparator);
1529
1530 if (list.isEmpty()) {
1531 StringBundler msg = new StringBundler(4);
1532
1533 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1534
1535 msg.append("categoryId=");
1536 msg.append(categoryId);
1537
1538 msg.append(StringPool.CLOSE_CURLY_BRACE);
1539
1540 throw new NoSuchMessageException(msg.toString());
1541 }
1542 else {
1543 return list.get(0);
1544 }
1545 }
1546
1547 public MBMessage findByCategoryId_Last(long categoryId,
1548 OrderByComparator orderByComparator)
1549 throws NoSuchMessageException, SystemException {
1550 int count = countByCategoryId(categoryId);
1551
1552 List<MBMessage> list = findByCategoryId(categoryId, count - 1, count,
1553 orderByComparator);
1554
1555 if (list.isEmpty()) {
1556 StringBundler msg = new StringBundler(4);
1557
1558 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1559
1560 msg.append("categoryId=");
1561 msg.append(categoryId);
1562
1563 msg.append(StringPool.CLOSE_CURLY_BRACE);
1564
1565 throw new NoSuchMessageException(msg.toString());
1566 }
1567 else {
1568 return list.get(0);
1569 }
1570 }
1571
1572 public MBMessage[] findByCategoryId_PrevAndNext(long messageId,
1573 long categoryId, OrderByComparator orderByComparator)
1574 throws NoSuchMessageException, SystemException {
1575 MBMessage mbMessage = findByPrimaryKey(messageId);
1576
1577 Session session = null;
1578
1579 try {
1580 session = openSession();
1581
1582 MBMessage[] array = new MBMessageImpl[3];
1583
1584 array[0] = getByCategoryId_PrevAndNext(session, mbMessage,
1585 categoryId, orderByComparator, true);
1586
1587 array[1] = mbMessage;
1588
1589 array[2] = getByCategoryId_PrevAndNext(session, mbMessage,
1590 categoryId, orderByComparator, false);
1591
1592 return array;
1593 }
1594 catch (Exception e) {
1595 throw processException(e);
1596 }
1597 finally {
1598 closeSession(session);
1599 }
1600 }
1601
1602 protected MBMessage getByCategoryId_PrevAndNext(Session session,
1603 MBMessage mbMessage, long categoryId,
1604 OrderByComparator orderByComparator, boolean previous) {
1605 StringBundler query = null;
1606
1607 if (orderByComparator != null) {
1608 query = new StringBundler(6 +
1609 (orderByComparator.getOrderByFields().length * 6));
1610 }
1611 else {
1612 query = new StringBundler(3);
1613 }
1614
1615 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1616
1617 query.append(_FINDER_COLUMN_CATEGORYID_CATEGORYID_2);
1618
1619 if (orderByComparator != null) {
1620 String[] orderByFields = orderByComparator.getOrderByFields();
1621
1622 if (orderByFields.length > 0) {
1623 query.append(WHERE_AND);
1624 }
1625
1626 for (int i = 0; i < orderByFields.length; i++) {
1627 query.append(_ORDER_BY_ENTITY_ALIAS);
1628 query.append(orderByFields[i]);
1629
1630 if ((i + 1) < orderByFields.length) {
1631 if (orderByComparator.isAscending() ^ previous) {
1632 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1633 }
1634 else {
1635 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1636 }
1637 }
1638 else {
1639 if (orderByComparator.isAscending() ^ previous) {
1640 query.append(WHERE_GREATER_THAN);
1641 }
1642 else {
1643 query.append(WHERE_LESSER_THAN);
1644 }
1645 }
1646 }
1647
1648 query.append(ORDER_BY_CLAUSE);
1649
1650 for (int i = 0; i < orderByFields.length; i++) {
1651 query.append(_ORDER_BY_ENTITY_ALIAS);
1652 query.append(orderByFields[i]);
1653
1654 if ((i + 1) < orderByFields.length) {
1655 if (orderByComparator.isAscending() ^ previous) {
1656 query.append(ORDER_BY_ASC_HAS_NEXT);
1657 }
1658 else {
1659 query.append(ORDER_BY_DESC_HAS_NEXT);
1660 }
1661 }
1662 else {
1663 if (orderByComparator.isAscending() ^ previous) {
1664 query.append(ORDER_BY_ASC);
1665 }
1666 else {
1667 query.append(ORDER_BY_DESC);
1668 }
1669 }
1670 }
1671 }
1672
1673 else {
1674 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1675 }
1676
1677 String sql = query.toString();
1678
1679 Query q = session.createQuery(sql);
1680
1681 q.setFirstResult(0);
1682 q.setMaxResults(2);
1683
1684 QueryPos qPos = QueryPos.getInstance(q);
1685
1686 qPos.add(categoryId);
1687
1688 if (orderByComparator != null) {
1689 Object[] values = orderByComparator.getOrderByValues(mbMessage);
1690
1691 for (Object value : values) {
1692 qPos.add(value);
1693 }
1694 }
1695
1696 List<MBMessage> list = q.list();
1697
1698 if (list.size() == 2) {
1699 return list.get(1);
1700 }
1701 else {
1702 return null;
1703 }
1704 }
1705
1706 public List<MBMessage> findByThreadId(long threadId)
1707 throws SystemException {
1708 return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1709 null);
1710 }
1711
1712 public List<MBMessage> findByThreadId(long threadId, int start, int end)
1713 throws SystemException {
1714 return findByThreadId(threadId, start, end, null);
1715 }
1716
1717 public List<MBMessage> findByThreadId(long threadId, int start, int end,
1718 OrderByComparator orderByComparator) throws SystemException {
1719 Object[] finderArgs = new Object[] {
1720 threadId,
1721
1722 String.valueOf(start), String.valueOf(end),
1723 String.valueOf(orderByComparator)
1724 };
1725
1726 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_THREADID,
1727 finderArgs, this);
1728
1729 if (list == null) {
1730 StringBundler query = null;
1731
1732 if (orderByComparator != null) {
1733 query = new StringBundler(3 +
1734 (orderByComparator.getOrderByFields().length * 3));
1735 }
1736 else {
1737 query = new StringBundler(3);
1738 }
1739
1740 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1741
1742 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
1743
1744 if (orderByComparator != null) {
1745 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1746 orderByComparator);
1747 }
1748
1749 else {
1750 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1751 }
1752
1753 String sql = query.toString();
1754
1755 Session session = null;
1756
1757 try {
1758 session = openSession();
1759
1760 Query q = session.createQuery(sql);
1761
1762 QueryPos qPos = QueryPos.getInstance(q);
1763
1764 qPos.add(threadId);
1765
1766 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
1767 end);
1768 }
1769 catch (Exception e) {
1770 throw processException(e);
1771 }
1772 finally {
1773 if (list == null) {
1774 list = new ArrayList<MBMessage>();
1775 }
1776
1777 cacheResult(list);
1778
1779 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_THREADID,
1780 finderArgs, list);
1781
1782 closeSession(session);
1783 }
1784 }
1785
1786 return list;
1787 }
1788
1789 public MBMessage findByThreadId_First(long threadId,
1790 OrderByComparator orderByComparator)
1791 throws NoSuchMessageException, SystemException {
1792 List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
1793
1794 if (list.isEmpty()) {
1795 StringBundler msg = new StringBundler(4);
1796
1797 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1798
1799 msg.append("threadId=");
1800 msg.append(threadId);
1801
1802 msg.append(StringPool.CLOSE_CURLY_BRACE);
1803
1804 throw new NoSuchMessageException(msg.toString());
1805 }
1806 else {
1807 return list.get(0);
1808 }
1809 }
1810
1811 public MBMessage findByThreadId_Last(long threadId,
1812 OrderByComparator orderByComparator)
1813 throws NoSuchMessageException, SystemException {
1814 int count = countByThreadId(threadId);
1815
1816 List<MBMessage> list = findByThreadId(threadId, count - 1, count,
1817 orderByComparator);
1818
1819 if (list.isEmpty()) {
1820 StringBundler msg = new StringBundler(4);
1821
1822 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1823
1824 msg.append("threadId=");
1825 msg.append(threadId);
1826
1827 msg.append(StringPool.CLOSE_CURLY_BRACE);
1828
1829 throw new NoSuchMessageException(msg.toString());
1830 }
1831 else {
1832 return list.get(0);
1833 }
1834 }
1835
1836 public MBMessage[] findByThreadId_PrevAndNext(long messageId,
1837 long threadId, OrderByComparator orderByComparator)
1838 throws NoSuchMessageException, SystemException {
1839 MBMessage mbMessage = findByPrimaryKey(messageId);
1840
1841 Session session = null;
1842
1843 try {
1844 session = openSession();
1845
1846 MBMessage[] array = new MBMessageImpl[3];
1847
1848 array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
1849 orderByComparator, true);
1850
1851 array[1] = mbMessage;
1852
1853 array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
1854 orderByComparator, false);
1855
1856 return array;
1857 }
1858 catch (Exception e) {
1859 throw processException(e);
1860 }
1861 finally {
1862 closeSession(session);
1863 }
1864 }
1865
1866 protected MBMessage getByThreadId_PrevAndNext(Session session,
1867 MBMessage mbMessage, long threadId,
1868 OrderByComparator orderByComparator, boolean previous) {
1869 StringBundler query = null;
1870
1871 if (orderByComparator != null) {
1872 query = new StringBundler(6 +
1873 (orderByComparator.getOrderByFields().length * 6));
1874 }
1875 else {
1876 query = new StringBundler(3);
1877 }
1878
1879 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1880
1881 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
1882
1883 if (orderByComparator != null) {
1884 String[] orderByFields = orderByComparator.getOrderByFields();
1885
1886 if (orderByFields.length > 0) {
1887 query.append(WHERE_AND);
1888 }
1889
1890 for (int i = 0; i < orderByFields.length; i++) {
1891 query.append(_ORDER_BY_ENTITY_ALIAS);
1892 query.append(orderByFields[i]);
1893
1894 if ((i + 1) < orderByFields.length) {
1895 if (orderByComparator.isAscending() ^ previous) {
1896 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1897 }
1898 else {
1899 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1900 }
1901 }
1902 else {
1903 if (orderByComparator.isAscending() ^ previous) {
1904 query.append(WHERE_GREATER_THAN);
1905 }
1906 else {
1907 query.append(WHERE_LESSER_THAN);
1908 }
1909 }
1910 }
1911
1912 query.append(ORDER_BY_CLAUSE);
1913
1914 for (int i = 0; i < orderByFields.length; i++) {
1915 query.append(_ORDER_BY_ENTITY_ALIAS);
1916 query.append(orderByFields[i]);
1917
1918 if ((i + 1) < orderByFields.length) {
1919 if (orderByComparator.isAscending() ^ previous) {
1920 query.append(ORDER_BY_ASC_HAS_NEXT);
1921 }
1922 else {
1923 query.append(ORDER_BY_DESC_HAS_NEXT);
1924 }
1925 }
1926 else {
1927 if (orderByComparator.isAscending() ^ previous) {
1928 query.append(ORDER_BY_ASC);
1929 }
1930 else {
1931 query.append(ORDER_BY_DESC);
1932 }
1933 }
1934 }
1935 }
1936
1937 else {
1938 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1939 }
1940
1941 String sql = query.toString();
1942
1943 Query q = session.createQuery(sql);
1944
1945 q.setFirstResult(0);
1946 q.setMaxResults(2);
1947
1948 QueryPos qPos = QueryPos.getInstance(q);
1949
1950 qPos.add(threadId);
1951
1952 if (orderByComparator != null) {
1953 Object[] values = orderByComparator.getOrderByValues(mbMessage);
1954
1955 for (Object value : values) {
1956 qPos.add(value);
1957 }
1958 }
1959
1960 List<MBMessage> list = q.list();
1961
1962 if (list.size() == 2) {
1963 return list.get(1);
1964 }
1965 else {
1966 return null;
1967 }
1968 }
1969
1970 public List<MBMessage> findByThreadReplies(long threadId)
1971 throws SystemException {
1972 return findByThreadReplies(threadId, QueryUtil.ALL_POS,
1973 QueryUtil.ALL_POS, null);
1974 }
1975
1976 public List<MBMessage> findByThreadReplies(long threadId, int start, int end)
1977 throws SystemException {
1978 return findByThreadReplies(threadId, start, end, null);
1979 }
1980
1981 public List<MBMessage> findByThreadReplies(long threadId, int start,
1982 int end, OrderByComparator orderByComparator) throws SystemException {
1983 Object[] finderArgs = new Object[] {
1984 threadId,
1985
1986 String.valueOf(start), String.valueOf(end),
1987 String.valueOf(orderByComparator)
1988 };
1989
1990 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_THREADREPLIES,
1991 finderArgs, this);
1992
1993 if (list == null) {
1994 StringBundler query = null;
1995
1996 if (orderByComparator != null) {
1997 query = new StringBundler(3 +
1998 (orderByComparator.getOrderByFields().length * 3));
1999 }
2000 else {
2001 query = new StringBundler(3);
2002 }
2003
2004 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2005
2006 query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
2007
2008 if (orderByComparator != null) {
2009 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2010 orderByComparator);
2011 }
2012
2013 else {
2014 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2015 }
2016
2017 String sql = query.toString();
2018
2019 Session session = null;
2020
2021 try {
2022 session = openSession();
2023
2024 Query q = session.createQuery(sql);
2025
2026 QueryPos qPos = QueryPos.getInstance(q);
2027
2028 qPos.add(threadId);
2029
2030 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2031 end);
2032 }
2033 catch (Exception e) {
2034 throw processException(e);
2035 }
2036 finally {
2037 if (list == null) {
2038 list = new ArrayList<MBMessage>();
2039 }
2040
2041 cacheResult(list);
2042
2043 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_THREADREPLIES,
2044 finderArgs, list);
2045
2046 closeSession(session);
2047 }
2048 }
2049
2050 return list;
2051 }
2052
2053 public MBMessage findByThreadReplies_First(long threadId,
2054 OrderByComparator orderByComparator)
2055 throws NoSuchMessageException, SystemException {
2056 List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
2057 orderByComparator);
2058
2059 if (list.isEmpty()) {
2060 StringBundler msg = new StringBundler(4);
2061
2062 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2063
2064 msg.append("threadId=");
2065 msg.append(threadId);
2066
2067 msg.append(StringPool.CLOSE_CURLY_BRACE);
2068
2069 throw new NoSuchMessageException(msg.toString());
2070 }
2071 else {
2072 return list.get(0);
2073 }
2074 }
2075
2076 public MBMessage findByThreadReplies_Last(long threadId,
2077 OrderByComparator orderByComparator)
2078 throws NoSuchMessageException, SystemException {
2079 int count = countByThreadReplies(threadId);
2080
2081 List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
2082 orderByComparator);
2083
2084 if (list.isEmpty()) {
2085 StringBundler msg = new StringBundler(4);
2086
2087 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2088
2089 msg.append("threadId=");
2090 msg.append(threadId);
2091
2092 msg.append(StringPool.CLOSE_CURLY_BRACE);
2093
2094 throw new NoSuchMessageException(msg.toString());
2095 }
2096 else {
2097 return list.get(0);
2098 }
2099 }
2100
2101 public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
2102 long threadId, OrderByComparator orderByComparator)
2103 throws NoSuchMessageException, SystemException {
2104 MBMessage mbMessage = findByPrimaryKey(messageId);
2105
2106 Session session = null;
2107
2108 try {
2109 session = openSession();
2110
2111 MBMessage[] array = new MBMessageImpl[3];
2112
2113 array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
2114 threadId, orderByComparator, true);
2115
2116 array[1] = mbMessage;
2117
2118 array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
2119 threadId, orderByComparator, false);
2120
2121 return array;
2122 }
2123 catch (Exception e) {
2124 throw processException(e);
2125 }
2126 finally {
2127 closeSession(session);
2128 }
2129 }
2130
2131 protected MBMessage getByThreadReplies_PrevAndNext(Session session,
2132 MBMessage mbMessage, long threadId,
2133 OrderByComparator orderByComparator, boolean previous) {
2134 StringBundler query = null;
2135
2136 if (orderByComparator != null) {
2137 query = new StringBundler(6 +
2138 (orderByComparator.getOrderByFields().length * 6));
2139 }
2140 else {
2141 query = new StringBundler(3);
2142 }
2143
2144 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2145
2146 query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
2147
2148 if (orderByComparator != null) {
2149 String[] orderByFields = orderByComparator.getOrderByFields();
2150
2151 if (orderByFields.length > 0) {
2152 query.append(WHERE_AND);
2153 }
2154
2155 for (int i = 0; i < orderByFields.length; i++) {
2156 query.append(_ORDER_BY_ENTITY_ALIAS);
2157 query.append(orderByFields[i]);
2158
2159 if ((i + 1) < orderByFields.length) {
2160 if (orderByComparator.isAscending() ^ previous) {
2161 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2162 }
2163 else {
2164 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2165 }
2166 }
2167 else {
2168 if (orderByComparator.isAscending() ^ previous) {
2169 query.append(WHERE_GREATER_THAN);
2170 }
2171 else {
2172 query.append(WHERE_LESSER_THAN);
2173 }
2174 }
2175 }
2176
2177 query.append(ORDER_BY_CLAUSE);
2178
2179 for (int i = 0; i < orderByFields.length; i++) {
2180 query.append(_ORDER_BY_ENTITY_ALIAS);
2181 query.append(orderByFields[i]);
2182
2183 if ((i + 1) < orderByFields.length) {
2184 if (orderByComparator.isAscending() ^ previous) {
2185 query.append(ORDER_BY_ASC_HAS_NEXT);
2186 }
2187 else {
2188 query.append(ORDER_BY_DESC_HAS_NEXT);
2189 }
2190 }
2191 else {
2192 if (orderByComparator.isAscending() ^ previous) {
2193 query.append(ORDER_BY_ASC);
2194 }
2195 else {
2196 query.append(ORDER_BY_DESC);
2197 }
2198 }
2199 }
2200 }
2201
2202 else {
2203 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2204 }
2205
2206 String sql = query.toString();
2207
2208 Query q = session.createQuery(sql);
2209
2210 q.setFirstResult(0);
2211 q.setMaxResults(2);
2212
2213 QueryPos qPos = QueryPos.getInstance(q);
2214
2215 qPos.add(threadId);
2216
2217 if (orderByComparator != null) {
2218 Object[] values = orderByComparator.getOrderByValues(mbMessage);
2219
2220 for (Object value : values) {
2221 qPos.add(value);
2222 }
2223 }
2224
2225 List<MBMessage> list = q.list();
2226
2227 if (list.size() == 2) {
2228 return list.get(1);
2229 }
2230 else {
2231 return null;
2232 }
2233 }
2234
2235 public List<MBMessage> findByG_U(long groupId, long userId)
2236 throws SystemException {
2237 return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2238 null);
2239 }
2240
2241 public List<MBMessage> findByG_U(long groupId, long userId, int start,
2242 int end) throws SystemException {
2243 return findByG_U(groupId, userId, start, end, null);
2244 }
2245
2246 public List<MBMessage> findByG_U(long groupId, long userId, int start,
2247 int end, OrderByComparator orderByComparator) throws SystemException {
2248 Object[] finderArgs = new Object[] {
2249 groupId, userId,
2250
2251 String.valueOf(start), String.valueOf(end),
2252 String.valueOf(orderByComparator)
2253 };
2254
2255 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
2256 finderArgs, this);
2257
2258 if (list == null) {
2259 StringBundler query = null;
2260
2261 if (orderByComparator != null) {
2262 query = new StringBundler(4 +
2263 (orderByComparator.getOrderByFields().length * 3));
2264 }
2265 else {
2266 query = new StringBundler(4);
2267 }
2268
2269 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2270
2271 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2272
2273 query.append(_FINDER_COLUMN_G_U_USERID_2);
2274
2275 if (orderByComparator != null) {
2276 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2277 orderByComparator);
2278 }
2279
2280 else {
2281 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2282 }
2283
2284 String sql = query.toString();
2285
2286 Session session = null;
2287
2288 try {
2289 session = openSession();
2290
2291 Query q = session.createQuery(sql);
2292
2293 QueryPos qPos = QueryPos.getInstance(q);
2294
2295 qPos.add(groupId);
2296
2297 qPos.add(userId);
2298
2299 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2300 end);
2301 }
2302 catch (Exception e) {
2303 throw processException(e);
2304 }
2305 finally {
2306 if (list == null) {
2307 list = new ArrayList<MBMessage>();
2308 }
2309
2310 cacheResult(list);
2311
2312 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U, finderArgs,
2313 list);
2314
2315 closeSession(session);
2316 }
2317 }
2318
2319 return list;
2320 }
2321
2322 public MBMessage findByG_U_First(long groupId, long userId,
2323 OrderByComparator orderByComparator)
2324 throws NoSuchMessageException, SystemException {
2325 List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
2326 orderByComparator);
2327
2328 if (list.isEmpty()) {
2329 StringBundler msg = new StringBundler(6);
2330
2331 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2332
2333 msg.append("groupId=");
2334 msg.append(groupId);
2335
2336 msg.append(", userId=");
2337 msg.append(userId);
2338
2339 msg.append(StringPool.CLOSE_CURLY_BRACE);
2340
2341 throw new NoSuchMessageException(msg.toString());
2342 }
2343 else {
2344 return list.get(0);
2345 }
2346 }
2347
2348 public MBMessage findByG_U_Last(long groupId, long userId,
2349 OrderByComparator orderByComparator)
2350 throws NoSuchMessageException, SystemException {
2351 int count = countByG_U(groupId, userId);
2352
2353 List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
2354 orderByComparator);
2355
2356 if (list.isEmpty()) {
2357 StringBundler msg = new StringBundler(6);
2358
2359 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2360
2361 msg.append("groupId=");
2362 msg.append(groupId);
2363
2364 msg.append(", userId=");
2365 msg.append(userId);
2366
2367 msg.append(StringPool.CLOSE_CURLY_BRACE);
2368
2369 throw new NoSuchMessageException(msg.toString());
2370 }
2371 else {
2372 return list.get(0);
2373 }
2374 }
2375
2376 public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
2377 long userId, OrderByComparator orderByComparator)
2378 throws NoSuchMessageException, SystemException {
2379 MBMessage mbMessage = findByPrimaryKey(messageId);
2380
2381 Session session = null;
2382
2383 try {
2384 session = openSession();
2385
2386 MBMessage[] array = new MBMessageImpl[3];
2387
2388 array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
2389 userId, orderByComparator, true);
2390
2391 array[1] = mbMessage;
2392
2393 array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
2394 userId, orderByComparator, false);
2395
2396 return array;
2397 }
2398 catch (Exception e) {
2399 throw processException(e);
2400 }
2401 finally {
2402 closeSession(session);
2403 }
2404 }
2405
2406 protected MBMessage getByG_U_PrevAndNext(Session session,
2407 MBMessage mbMessage, long groupId, long userId,
2408 OrderByComparator orderByComparator, boolean previous) {
2409 StringBundler query = null;
2410
2411 if (orderByComparator != null) {
2412 query = new StringBundler(6 +
2413 (orderByComparator.getOrderByFields().length * 6));
2414 }
2415 else {
2416 query = new StringBundler(3);
2417 }
2418
2419 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2420
2421 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2422
2423 query.append(_FINDER_COLUMN_G_U_USERID_2);
2424
2425 if (orderByComparator != null) {
2426 String[] orderByFields = orderByComparator.getOrderByFields();
2427
2428 if (orderByFields.length > 0) {
2429 query.append(WHERE_AND);
2430 }
2431
2432 for (int i = 0; i < orderByFields.length; i++) {
2433 query.append(_ORDER_BY_ENTITY_ALIAS);
2434 query.append(orderByFields[i]);
2435
2436 if ((i + 1) < orderByFields.length) {
2437 if (orderByComparator.isAscending() ^ previous) {
2438 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2439 }
2440 else {
2441 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2442 }
2443 }
2444 else {
2445 if (orderByComparator.isAscending() ^ previous) {
2446 query.append(WHERE_GREATER_THAN);
2447 }
2448 else {
2449 query.append(WHERE_LESSER_THAN);
2450 }
2451 }
2452 }
2453
2454 query.append(ORDER_BY_CLAUSE);
2455
2456 for (int i = 0; i < orderByFields.length; i++) {
2457 query.append(_ORDER_BY_ENTITY_ALIAS);
2458 query.append(orderByFields[i]);
2459
2460 if ((i + 1) < orderByFields.length) {
2461 if (orderByComparator.isAscending() ^ previous) {
2462 query.append(ORDER_BY_ASC_HAS_NEXT);
2463 }
2464 else {
2465 query.append(ORDER_BY_DESC_HAS_NEXT);
2466 }
2467 }
2468 else {
2469 if (orderByComparator.isAscending() ^ previous) {
2470 query.append(ORDER_BY_ASC);
2471 }
2472 else {
2473 query.append(ORDER_BY_DESC);
2474 }
2475 }
2476 }
2477 }
2478
2479 else {
2480 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2481 }
2482
2483 String sql = query.toString();
2484
2485 Query q = session.createQuery(sql);
2486
2487 q.setFirstResult(0);
2488 q.setMaxResults(2);
2489
2490 QueryPos qPos = QueryPos.getInstance(q);
2491
2492 qPos.add(groupId);
2493
2494 qPos.add(userId);
2495
2496 if (orderByComparator != null) {
2497 Object[] values = orderByComparator.getOrderByValues(mbMessage);
2498
2499 for (Object value : values) {
2500 qPos.add(value);
2501 }
2502 }
2503
2504 List<MBMessage> list = q.list();
2505
2506 if (list.size() == 2) {
2507 return list.get(1);
2508 }
2509 else {
2510 return null;
2511 }
2512 }
2513
2514 public List<MBMessage> findByC_C(long classNameId, long classPK)
2515 throws SystemException {
2516 return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
2517 QueryUtil.ALL_POS, null);
2518 }
2519
2520 public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
2521 int end) throws SystemException {
2522 return findByC_C(classNameId, classPK, start, end, null);
2523 }
2524
2525 public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
2526 int end, OrderByComparator orderByComparator) throws SystemException {
2527 Object[] finderArgs = new Object[] {
2528 classNameId, classPK,
2529
2530 String.valueOf(start), String.valueOf(end),
2531 String.valueOf(orderByComparator)
2532 };
2533
2534 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
2535 finderArgs, this);
2536
2537 if (list == null) {
2538 StringBundler query = null;
2539
2540 if (orderByComparator != null) {
2541 query = new StringBundler(4 +
2542 (orderByComparator.getOrderByFields().length * 3));
2543 }
2544 else {
2545 query = new StringBundler(4);
2546 }
2547
2548 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2549
2550 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2551
2552 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2553
2554 if (orderByComparator != null) {
2555 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2556 orderByComparator);
2557 }
2558
2559 else {
2560 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2561 }
2562
2563 String sql = query.toString();
2564
2565 Session session = null;
2566
2567 try {
2568 session = openSession();
2569
2570 Query q = session.createQuery(sql);
2571
2572 QueryPos qPos = QueryPos.getInstance(q);
2573
2574 qPos.add(classNameId);
2575
2576 qPos.add(classPK);
2577
2578 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2579 end);
2580 }
2581 catch (Exception e) {
2582 throw processException(e);
2583 }
2584 finally {
2585 if (list == null) {
2586 list = new ArrayList<MBMessage>();
2587 }
2588
2589 cacheResult(list);
2590
2591 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
2592 list);
2593
2594 closeSession(session);
2595 }
2596 }
2597
2598 return list;
2599 }
2600
2601 public MBMessage findByC_C_First(long classNameId, long classPK,
2602 OrderByComparator orderByComparator)
2603 throws NoSuchMessageException, SystemException {
2604 List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
2605 orderByComparator);
2606
2607 if (list.isEmpty()) {
2608 StringBundler msg = new StringBundler(6);
2609
2610 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2611
2612 msg.append("classNameId=");
2613 msg.append(classNameId);
2614
2615 msg.append(", classPK=");
2616 msg.append(classPK);
2617
2618 msg.append(StringPool.CLOSE_CURLY_BRACE);
2619
2620 throw new NoSuchMessageException(msg.toString());
2621 }
2622 else {
2623 return list.get(0);
2624 }
2625 }
2626
2627 public MBMessage findByC_C_Last(long classNameId, long classPK,
2628 OrderByComparator orderByComparator)
2629 throws NoSuchMessageException, SystemException {
2630 int count = countByC_C(classNameId, classPK);
2631
2632 List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
2633 count, orderByComparator);
2634
2635 if (list.isEmpty()) {
2636 StringBundler msg = new StringBundler(6);
2637
2638 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2639
2640 msg.append("classNameId=");
2641 msg.append(classNameId);
2642
2643 msg.append(", classPK=");
2644 msg.append(classPK);
2645
2646 msg.append(StringPool.CLOSE_CURLY_BRACE);
2647
2648 throw new NoSuchMessageException(msg.toString());
2649 }
2650 else {
2651 return list.get(0);
2652 }
2653 }
2654
2655 public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
2656 long classPK, OrderByComparator orderByComparator)
2657 throws NoSuchMessageException, SystemException {
2658 MBMessage mbMessage = findByPrimaryKey(messageId);
2659
2660 Session session = null;
2661
2662 try {
2663 session = openSession();
2664
2665 MBMessage[] array = new MBMessageImpl[3];
2666
2667 array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
2668 classPK, orderByComparator, true);
2669
2670 array[1] = mbMessage;
2671
2672 array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
2673 classPK, orderByComparator, false);
2674
2675 return array;
2676 }
2677 catch (Exception e) {
2678 throw processException(e);
2679 }
2680 finally {
2681 closeSession(session);
2682 }
2683 }
2684
2685 protected MBMessage getByC_C_PrevAndNext(Session session,
2686 MBMessage mbMessage, long classNameId, long classPK,
2687 OrderByComparator orderByComparator, boolean previous) {
2688 StringBundler query = null;
2689
2690 if (orderByComparator != null) {
2691 query = new StringBundler(6 +
2692 (orderByComparator.getOrderByFields().length * 6));
2693 }
2694 else {
2695 query = new StringBundler(3);
2696 }
2697
2698 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2699
2700 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2701
2702 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2703
2704 if (orderByComparator != null) {
2705 String[] orderByFields = orderByComparator.getOrderByFields();
2706
2707 if (orderByFields.length > 0) {
2708 query.append(WHERE_AND);
2709 }
2710
2711 for (int i = 0; i < orderByFields.length; i++) {
2712 query.append(_ORDER_BY_ENTITY_ALIAS);
2713 query.append(orderByFields[i]);
2714
2715 if ((i + 1) < orderByFields.length) {
2716 if (orderByComparator.isAscending() ^ previous) {
2717 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2718 }
2719 else {
2720 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2721 }
2722 }
2723 else {
2724 if (orderByComparator.isAscending() ^ previous) {
2725 query.append(WHERE_GREATER_THAN);
2726 }
2727 else {
2728 query.append(WHERE_LESSER_THAN);
2729 }
2730 }
2731 }
2732
2733 query.append(ORDER_BY_CLAUSE);
2734
2735 for (int i = 0; i < orderByFields.length; i++) {
2736 query.append(_ORDER_BY_ENTITY_ALIAS);
2737 query.append(orderByFields[i]);
2738
2739 if ((i + 1) < orderByFields.length) {
2740 if (orderByComparator.isAscending() ^ previous) {
2741 query.append(ORDER_BY_ASC_HAS_NEXT);
2742 }
2743 else {
2744 query.append(ORDER_BY_DESC_HAS_NEXT);
2745 }
2746 }
2747 else {
2748 if (orderByComparator.isAscending() ^ previous) {
2749 query.append(ORDER_BY_ASC);
2750 }
2751 else {
2752 query.append(ORDER_BY_DESC);
2753 }
2754 }
2755 }
2756 }
2757
2758 else {
2759 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2760 }
2761
2762 String sql = query.toString();
2763
2764 Query q = session.createQuery(sql);
2765
2766 q.setFirstResult(0);
2767 q.setMaxResults(2);
2768
2769 QueryPos qPos = QueryPos.getInstance(q);
2770
2771 qPos.add(classNameId);
2772
2773 qPos.add(classPK);
2774
2775 if (orderByComparator != null) {
2776 Object[] values = orderByComparator.getOrderByValues(mbMessage);
2777
2778 for (Object value : values) {
2779 qPos.add(value);
2780 }
2781 }
2782
2783 List<MBMessage> list = q.list();
2784
2785 if (list.size() == 2) {
2786 return list.get(1);
2787 }
2788 else {
2789 return null;
2790 }
2791 }
2792
2793 public List<MBMessage> findByC_T(long categoryId, long threadId)
2794 throws SystemException {
2795 return findByC_T(categoryId, threadId, QueryUtil.ALL_POS,
2796 QueryUtil.ALL_POS, null);
2797 }
2798
2799 public List<MBMessage> findByC_T(long categoryId, long threadId, int start,
2800 int end) throws SystemException {
2801 return findByC_T(categoryId, threadId, start, end, null);
2802 }
2803
2804 public List<MBMessage> findByC_T(long categoryId, long threadId, int start,
2805 int end, OrderByComparator orderByComparator) throws SystemException {
2806 Object[] finderArgs = new Object[] {
2807 categoryId, threadId,
2808
2809 String.valueOf(start), String.valueOf(end),
2810 String.valueOf(orderByComparator)
2811 };
2812
2813 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_T,
2814 finderArgs, this);
2815
2816 if (list == null) {
2817 StringBundler query = null;
2818
2819 if (orderByComparator != null) {
2820 query = new StringBundler(4 +
2821 (orderByComparator.getOrderByFields().length * 3));
2822 }
2823 else {
2824 query = new StringBundler(4);
2825 }
2826
2827 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2828
2829 query.append(_FINDER_COLUMN_C_T_CATEGORYID_2);
2830
2831 query.append(_FINDER_COLUMN_C_T_THREADID_2);
2832
2833 if (orderByComparator != null) {
2834 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2835 orderByComparator);
2836 }
2837
2838 else {
2839 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2840 }
2841
2842 String sql = query.toString();
2843
2844 Session session = null;
2845
2846 try {
2847 session = openSession();
2848
2849 Query q = session.createQuery(sql);
2850
2851 QueryPos qPos = QueryPos.getInstance(q);
2852
2853 qPos.add(categoryId);
2854
2855 qPos.add(threadId);
2856
2857 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
2858 end);
2859 }
2860 catch (Exception e) {
2861 throw processException(e);
2862 }
2863 finally {
2864 if (list == null) {
2865 list = new ArrayList<MBMessage>();
2866 }
2867
2868 cacheResult(list);
2869
2870 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_T, finderArgs,
2871 list);
2872
2873 closeSession(session);
2874 }
2875 }
2876
2877 return list;
2878 }
2879
2880 public MBMessage findByC_T_First(long categoryId, long threadId,
2881 OrderByComparator orderByComparator)
2882 throws NoSuchMessageException, SystemException {
2883 List<MBMessage> list = findByC_T(categoryId, threadId, 0, 1,
2884 orderByComparator);
2885
2886 if (list.isEmpty()) {
2887 StringBundler msg = new StringBundler(6);
2888
2889 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2890
2891 msg.append("categoryId=");
2892 msg.append(categoryId);
2893
2894 msg.append(", threadId=");
2895 msg.append(threadId);
2896
2897 msg.append(StringPool.CLOSE_CURLY_BRACE);
2898
2899 throw new NoSuchMessageException(msg.toString());
2900 }
2901 else {
2902 return list.get(0);
2903 }
2904 }
2905
2906 public MBMessage findByC_T_Last(long categoryId, long threadId,
2907 OrderByComparator orderByComparator)
2908 throws NoSuchMessageException, SystemException {
2909 int count = countByC_T(categoryId, threadId);
2910
2911 List<MBMessage> list = findByC_T(categoryId, threadId, count - 1,
2912 count, orderByComparator);
2913
2914 if (list.isEmpty()) {
2915 StringBundler msg = new StringBundler(6);
2916
2917 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2918
2919 msg.append("categoryId=");
2920 msg.append(categoryId);
2921
2922 msg.append(", threadId=");
2923 msg.append(threadId);
2924
2925 msg.append(StringPool.CLOSE_CURLY_BRACE);
2926
2927 throw new NoSuchMessageException(msg.toString());
2928 }
2929 else {
2930 return list.get(0);
2931 }
2932 }
2933
2934 public MBMessage[] findByC_T_PrevAndNext(long messageId, long categoryId,
2935 long threadId, OrderByComparator orderByComparator)
2936 throws NoSuchMessageException, SystemException {
2937 MBMessage mbMessage = findByPrimaryKey(messageId);
2938
2939 Session session = null;
2940
2941 try {
2942 session = openSession();
2943
2944 MBMessage[] array = new MBMessageImpl[3];
2945
2946 array[0] = getByC_T_PrevAndNext(session, mbMessage, categoryId,
2947 threadId, orderByComparator, true);
2948
2949 array[1] = mbMessage;
2950
2951 array[2] = getByC_T_PrevAndNext(session, mbMessage, categoryId,
2952 threadId, orderByComparator, false);
2953
2954 return array;
2955 }
2956 catch (Exception e) {
2957 throw processException(e);
2958 }
2959 finally {
2960 closeSession(session);
2961 }
2962 }
2963
2964 protected MBMessage getByC_T_PrevAndNext(Session session,
2965 MBMessage mbMessage, long categoryId, long threadId,
2966 OrderByComparator orderByComparator, boolean previous) {
2967 StringBundler query = null;
2968
2969 if (orderByComparator != null) {
2970 query = new StringBundler(6 +
2971 (orderByComparator.getOrderByFields().length * 6));
2972 }
2973 else {
2974 query = new StringBundler(3);
2975 }
2976
2977 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2978
2979 query.append(_FINDER_COLUMN_C_T_CATEGORYID_2);
2980
2981 query.append(_FINDER_COLUMN_C_T_THREADID_2);
2982
2983 if (orderByComparator != null) {
2984 String[] orderByFields = orderByComparator.getOrderByFields();
2985
2986 if (orderByFields.length > 0) {
2987 query.append(WHERE_AND);
2988 }
2989
2990 for (int i = 0; i < orderByFields.length; i++) {
2991 query.append(_ORDER_BY_ENTITY_ALIAS);
2992 query.append(orderByFields[i]);
2993
2994 if ((i + 1) < orderByFields.length) {
2995 if (orderByComparator.isAscending() ^ previous) {
2996 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2997 }
2998 else {
2999 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3000 }
3001 }
3002 else {
3003 if (orderByComparator.isAscending() ^ previous) {
3004 query.append(WHERE_GREATER_THAN);
3005 }
3006 else {
3007 query.append(WHERE_LESSER_THAN);
3008 }
3009 }
3010 }
3011
3012 query.append(ORDER_BY_CLAUSE);
3013
3014 for (int i = 0; i < orderByFields.length; i++) {
3015 query.append(_ORDER_BY_ENTITY_ALIAS);
3016 query.append(orderByFields[i]);
3017
3018 if ((i + 1) < orderByFields.length) {
3019 if (orderByComparator.isAscending() ^ previous) {
3020 query.append(ORDER_BY_ASC_HAS_NEXT);
3021 }
3022 else {
3023 query.append(ORDER_BY_DESC_HAS_NEXT);
3024 }
3025 }
3026 else {
3027 if (orderByComparator.isAscending() ^ previous) {
3028 query.append(ORDER_BY_ASC);
3029 }
3030 else {
3031 query.append(ORDER_BY_DESC);
3032 }
3033 }
3034 }
3035 }
3036
3037 else {
3038 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3039 }
3040
3041 String sql = query.toString();
3042
3043 Query q = session.createQuery(sql);
3044
3045 q.setFirstResult(0);
3046 q.setMaxResults(2);
3047
3048 QueryPos qPos = QueryPos.getInstance(q);
3049
3050 qPos.add(categoryId);
3051
3052 qPos.add(threadId);
3053
3054 if (orderByComparator != null) {
3055 Object[] values = orderByComparator.getOrderByValues(mbMessage);
3056
3057 for (Object value : values) {
3058 qPos.add(value);
3059 }
3060 }
3061
3062 List<MBMessage> list = q.list();
3063
3064 if (list.size() == 2) {
3065 return list.get(1);
3066 }
3067 else {
3068 return null;
3069 }
3070 }
3071
3072 public List<MBMessage> findByT_P(long threadId, long parentMessageId)
3073 throws SystemException {
3074 return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
3075 QueryUtil.ALL_POS, null);
3076 }
3077
3078 public List<MBMessage> findByT_P(long threadId, long parentMessageId,
3079 int start, int end) throws SystemException {
3080 return findByT_P(threadId, parentMessageId, start, end, null);
3081 }
3082
3083 public List<MBMessage> findByT_P(long threadId, long parentMessageId,
3084 int start, int end, OrderByComparator orderByComparator)
3085 throws SystemException {
3086 Object[] finderArgs = new Object[] {
3087 threadId, parentMessageId,
3088
3089 String.valueOf(start), String.valueOf(end),
3090 String.valueOf(orderByComparator)
3091 };
3092
3093 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_P,
3094 finderArgs, this);
3095
3096 if (list == null) {
3097 StringBundler query = null;
3098
3099 if (orderByComparator != null) {
3100 query = new StringBundler(4 +
3101 (orderByComparator.getOrderByFields().length * 3));
3102 }
3103 else {
3104 query = new StringBundler(4);
3105 }
3106
3107 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3108
3109 query.append(_FINDER_COLUMN_T_P_THREADID_2);
3110
3111 query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
3112
3113 if (orderByComparator != null) {
3114 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3115 orderByComparator);
3116 }
3117
3118 else {
3119 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3120 }
3121
3122 String sql = query.toString();
3123
3124 Session session = null;
3125
3126 try {
3127 session = openSession();
3128
3129 Query q = session.createQuery(sql);
3130
3131 QueryPos qPos = QueryPos.getInstance(q);
3132
3133 qPos.add(threadId);
3134
3135 qPos.add(parentMessageId);
3136
3137 list = (List<MBMessage>)QueryUtil.list(q, getDialect(), start,
3138 end);
3139 }
3140 catch (Exception e) {
3141 throw processException(e);
3142 }
3143 finally {
3144 if (list == null) {
3145 list = new ArrayList<MBMessage>();
3146 }
3147
3148 cacheResult(list);
3149
3150 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_P, finderArgs,
3151 list);
3152
3153 closeSession(session);
3154 }
3155 }
3156
3157 return list;
3158 }
3159
3160 public MBMessage findByT_P_First(long threadId, long parentMessageId,
3161 OrderByComparator orderByComparator)
3162 throws NoSuchMessageException, SystemException {
3163 List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
3164 orderByComparator);
3165
3166 if (list.isEmpty()) {
3167 StringBundler msg = new StringBundler(6);
3168
3169 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3170
3171 msg.append("threadId=");
3172 msg.append(threadId);
3173
3174 msg.append(", parentMessageId=");
3175 msg.append(parentMessageId);
3176
3177 msg.append(StringPool.CLOSE_CURLY_BRACE);
3178
3179 throw new NoSuchMessageException(msg.toString());
3180 }
3181 else {
3182 return list.get(0);
3183 }
3184 }
3185
3186 public MBMessage findByT_P_Last(long threadId, long parentMessageId,
3187 OrderByComparator orderByComparator)
3188 throws NoSuchMessageException, SystemException {
3189 int count = countByT_P(threadId, parentMessageId);
3190
3191 List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
3192 count, orderByComparator);
3193
3194 if (list.isEmpty()) {
3195 StringBundler msg = new StringBundler(6);
3196
3197 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3198
3199 msg.append("threadId=");
3200 msg.append(threadId);
3201
3202 msg.append(", parentMessageId=");
3203 msg.append(parentMessageId);
3204
3205 msg.append(StringPool.CLOSE_CURLY_BRACE);
3206
3207 throw new NoSuchMessageException(msg.toString());
3208 }
3209 else {
3210 return list.get(0);
3211 }
3212 }
3213
3214 public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
3215 long parentMessageId, OrderByComparator orderByComparator)
3216 throws NoSuchMessageException, SystemException {
3217 MBMessage mbMessage = findByPrimaryKey(messageId);
3218
3219 Session session = null;
3220
3221 try {
3222 session = openSession();
3223
3224 MBMessage[] array = new MBMessageImpl[3];
3225
3226 array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
3227 parentMessageId, orderByComparator, true);
3228
3229 array[1] = mbMessage;
3230
3231 array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
3232 parentMessageId, orderByComparator, false);
3233
3234 return array;
3235 }
3236 catch (Exception e) {
3237 throw processException(e);
3238 }
3239 finally {
3240 closeSession(session);
3241 }
3242 }
3243
3244 protected MBMessage getByT_P_PrevAndNext(Session session,
3245 MBMessage mbMessage, long threadId, long parentMessageId,
3246 OrderByComparator orderByComparator, boolean previous) {
3247 StringBundler query = null;
3248
3249 if (orderByComparator != null) {
3250 query = new StringBundler(6 +
3251 (orderByComparator.getOrderByFields().length * 6));
3252 }
3253 else {
3254 query = new StringBundler(3);
3255 }
3256
3257 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3258
3259 query.append(_FINDER_COLUMN_T_P_THREADID_2);
3260
3261 query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
3262
3263 if (orderByComparator != null) {
3264 String[] orderByFields = orderByComparator.getOrderByFields();
3265
3266 if (orderByFields.length > 0) {
3267 query.append(WHERE_AND);
3268 }
3269
3270 for (int i = 0; i < orderByFields.length; i++) {
3271 query.append(_ORDER_BY_ENTITY_ALIAS);
3272 query.append(orderByFields[i]);
3273
3274 if ((i + 1) < orderByFields.length) {
3275 if (orderByComparator.isAscending() ^ previous) {
3276 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3277 }
3278 else {
3279 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3280 }
3281 }
3282 else {
3283 if (orderByComparator.isAscending() ^ previous) {
3284 query.append(WHERE_GREATER_THAN);
3285 }
3286 else {
3287 query.append(WHERE_LESSER_THAN);
3288 }
3289 }
3290 }
3291
3292 query.append(ORDER_BY_CLAUSE);
3293
3294 for (int i = 0; i < orderByFields.length; i++) {
3295 query.append(_ORDER_BY_ENTITY_ALIAS);
3296 query.append(orderByFields[i]);
3297
3298 if ((i + 1) < orderByFields.length) {
3299 if (orderByComparator.isAscending() ^ previous) {
3300 query.append(ORDER_BY_ASC_HAS_NEXT);
3301 }
3302 else {
3303 query.append(ORDER_BY_DESC_HAS_NEXT);
3304 }
3305 }
3306 else {
3307 if (orderByComparator.isAscending() ^ previous) {
3308 query.append(ORDER_BY_ASC);
3309 }
3310 else {
3311 query.append(ORDER_BY_DESC);
3312 }
3313 }
3314 }
3315 }
3316
3317 else {
3318 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3319 }
3320
3321 String sql = query.toString();
3322
3323 Query q = session.createQuery(sql);
3324
3325 q.setFirstResult(0);
3326 q.setMaxResults(2);
3327
3328 QueryPos qPos = QueryPos.getInstance(q);
3329
3330 qPos.add(threadId);
3331
3332 qPos.add(parentMessageId);
3333
3334 if (orderByComparator != null) {
3335 Object[] values = orderByComparator.getOrderByValues(mbMessage);
3336
3337 for (Object value : values) {
3338 qPos.add(value);
3339 }
3340 }
3341
3342 List<MBMessage> list = q.list();
3343
3344 if (list.size() == 2) {
3345 return list.get(1);
3346 }
3347 else {
3348 return null;
3349 }
3350 }
3351
3352 public List<MBMessage> findAll() throws SystemException {
3353 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3354 }
3355
3356 public List<MBMessage> findAll(int start, int end)
3357 throws SystemException {
3358 return findAll(start, end, null);
3359 }
3360
3361 public List<MBMessage> findAll(int start, int end,
3362 OrderByComparator orderByComparator) throws SystemException {
3363 Object[] finderArgs = new Object[] {
3364 String.valueOf(start), String.valueOf(end),
3365 String.valueOf(orderByComparator)
3366 };
3367
3368 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
3369 finderArgs, this);
3370
3371 if (list == null) {
3372 StringBundler query = null;
3373 String sql = null;
3374
3375 if (orderByComparator != null) {
3376 query = new StringBundler(2 +
3377 (orderByComparator.getOrderByFields().length * 3));
3378
3379 query.append(_SQL_SELECT_MBMESSAGE);
3380
3381 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3382 orderByComparator);
3383
3384 sql = query.toString();
3385 }
3386 else {
3387 sql = _SQL_SELECT_MBMESSAGE.concat(MBMessageModelImpl.ORDER_BY_JPQL);
3388 }
3389
3390 Session session = null;
3391
3392 try {
3393 session = openSession();
3394
3395 Query q = session.createQuery(sql);
3396
3397 if (orderByComparator == null) {
3398 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3399 start, end, false);
3400
3401 Collections.sort(list);
3402 }
3403 else {
3404 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3405 start, end);
3406 }
3407 }
3408 catch (Exception e) {
3409 throw processException(e);
3410 }
3411 finally {
3412 if (list == null) {
3413 list = new ArrayList<MBMessage>();
3414 }
3415
3416 cacheResult(list);
3417
3418 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
3419
3420 closeSession(session);
3421 }
3422 }
3423
3424 return list;
3425 }
3426
3427 public void removeByUuid(String uuid) throws SystemException {
3428 for (MBMessage mbMessage : findByUuid(uuid)) {
3429 remove(mbMessage);
3430 }
3431 }
3432
3433 public void removeByUUID_G(String uuid, long groupId)
3434 throws NoSuchMessageException, SystemException {
3435 MBMessage mbMessage = findByUUID_G(uuid, groupId);
3436
3437 remove(mbMessage);
3438 }
3439
3440 public void removeByCompanyId(long companyId) throws SystemException {
3441 for (MBMessage mbMessage : findByCompanyId(companyId)) {
3442 remove(mbMessage);
3443 }
3444 }
3445
3446 public void removeByGroupId(long groupId) throws SystemException {
3447 for (MBMessage mbMessage : findByGroupId(groupId)) {
3448 remove(mbMessage);
3449 }
3450 }
3451
3452 public void removeByCategoryId(long categoryId) throws SystemException {
3453 for (MBMessage mbMessage : findByCategoryId(categoryId)) {
3454 remove(mbMessage);
3455 }
3456 }
3457
3458 public void removeByThreadId(long threadId) throws SystemException {
3459 for (MBMessage mbMessage : findByThreadId(threadId)) {
3460 remove(mbMessage);
3461 }
3462 }
3463
3464 public void removeByThreadReplies(long threadId) throws SystemException {
3465 for (MBMessage mbMessage : findByThreadReplies(threadId)) {
3466 remove(mbMessage);
3467 }
3468 }
3469
3470 public void removeByG_U(long groupId, long userId)
3471 throws SystemException {
3472 for (MBMessage mbMessage : findByG_U(groupId, userId)) {
3473 remove(mbMessage);
3474 }
3475 }
3476
3477 public void removeByC_C(long classNameId, long classPK)
3478 throws SystemException {
3479 for (MBMessage mbMessage : findByC_C(classNameId, classPK)) {
3480 remove(mbMessage);
3481 }
3482 }
3483
3484 public void removeByC_T(long categoryId, long threadId)
3485 throws SystemException {
3486 for (MBMessage mbMessage : findByC_T(categoryId, threadId)) {
3487 remove(mbMessage);
3488 }
3489 }
3490
3491 public void removeByT_P(long threadId, long parentMessageId)
3492 throws SystemException {
3493 for (MBMessage mbMessage : findByT_P(threadId, parentMessageId)) {
3494 remove(mbMessage);
3495 }
3496 }
3497
3498 public void removeAll() throws SystemException {
3499 for (MBMessage mbMessage : findAll()) {
3500 remove(mbMessage);
3501 }
3502 }
3503
3504 public int countByUuid(String uuid) throws SystemException {
3505 Object[] finderArgs = new Object[] { uuid };
3506
3507 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
3508 finderArgs, this);
3509
3510 if (count == null) {
3511 StringBundler query = new StringBundler(2);
3512
3513 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3514
3515 if (uuid == null) {
3516 query.append(_FINDER_COLUMN_UUID_UUID_1);
3517 }
3518 else {
3519 if (uuid.equals(StringPool.BLANK)) {
3520 query.append(_FINDER_COLUMN_UUID_UUID_3);
3521 }
3522 else {
3523 query.append(_FINDER_COLUMN_UUID_UUID_2);
3524 }
3525 }
3526
3527 String sql = query.toString();
3528
3529 Session session = null;
3530
3531 try {
3532 session = openSession();
3533
3534 Query q = session.createQuery(sql);
3535
3536 QueryPos qPos = QueryPos.getInstance(q);
3537
3538 if (uuid != null) {
3539 qPos.add(uuid);
3540 }
3541
3542 count = (Long)q.uniqueResult();
3543 }
3544 catch (Exception e) {
3545 throw processException(e);
3546 }
3547 finally {
3548 if (count == null) {
3549 count = Long.valueOf(0);
3550 }
3551
3552 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
3553 finderArgs, count);
3554
3555 closeSession(session);
3556 }
3557 }
3558
3559 return count.intValue();
3560 }
3561
3562 public int countByUUID_G(String uuid, long groupId)
3563 throws SystemException {
3564 Object[] finderArgs = new Object[] { uuid, groupId };
3565
3566 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
3567 finderArgs, this);
3568
3569 if (count == null) {
3570 StringBundler query = new StringBundler(3);
3571
3572 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3573
3574 if (uuid == null) {
3575 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
3576 }
3577 else {
3578 if (uuid.equals(StringPool.BLANK)) {
3579 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
3580 }
3581 else {
3582 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
3583 }
3584 }
3585
3586 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
3587
3588 String sql = query.toString();
3589
3590 Session session = null;
3591
3592 try {
3593 session = openSession();
3594
3595 Query q = session.createQuery(sql);
3596
3597 QueryPos qPos = QueryPos.getInstance(q);
3598
3599 if (uuid != null) {
3600 qPos.add(uuid);
3601 }
3602
3603 qPos.add(groupId);
3604
3605 count = (Long)q.uniqueResult();
3606 }
3607 catch (Exception e) {
3608 throw processException(e);
3609 }
3610 finally {
3611 if (count == null) {
3612 count = Long.valueOf(0);
3613 }
3614
3615 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
3616 finderArgs, count);
3617
3618 closeSession(session);
3619 }
3620 }
3621
3622 return count.intValue();
3623 }
3624
3625 public int countByCompanyId(long companyId) throws SystemException {
3626 Object[] finderArgs = new Object[] { companyId };
3627
3628 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
3629 finderArgs, this);
3630
3631 if (count == null) {
3632 StringBundler query = new StringBundler(2);
3633
3634 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3635
3636 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3637
3638 String sql = query.toString();
3639
3640 Session session = null;
3641
3642 try {
3643 session = openSession();
3644
3645 Query q = session.createQuery(sql);
3646
3647 QueryPos qPos = QueryPos.getInstance(q);
3648
3649 qPos.add(companyId);
3650
3651 count = (Long)q.uniqueResult();
3652 }
3653 catch (Exception e) {
3654 throw processException(e);
3655 }
3656 finally {
3657 if (count == null) {
3658 count = Long.valueOf(0);
3659 }
3660
3661 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
3662 finderArgs, count);
3663
3664 closeSession(session);
3665 }
3666 }
3667
3668 return count.intValue();
3669 }
3670
3671 public int countByGroupId(long groupId) throws SystemException {
3672 Object[] finderArgs = new Object[] { groupId };
3673
3674 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
3675 finderArgs, this);
3676
3677 if (count == null) {
3678 StringBundler query = new StringBundler(2);
3679
3680 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3681
3682 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3683
3684 String sql = query.toString();
3685
3686 Session session = null;
3687
3688 try {
3689 session = openSession();
3690
3691 Query q = session.createQuery(sql);
3692
3693 QueryPos qPos = QueryPos.getInstance(q);
3694
3695 qPos.add(groupId);
3696
3697 count = (Long)q.uniqueResult();
3698 }
3699 catch (Exception e) {
3700 throw processException(e);
3701 }
3702 finally {
3703 if (count == null) {
3704 count = Long.valueOf(0);
3705 }
3706
3707 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
3708 finderArgs, count);
3709
3710 closeSession(session);
3711 }
3712 }
3713
3714 return count.intValue();
3715 }
3716
3717 public int countByCategoryId(long categoryId) throws SystemException {
3718 Object[] finderArgs = new Object[] { categoryId };
3719
3720 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CATEGORYID,
3721 finderArgs, this);
3722
3723 if (count == null) {
3724 StringBundler query = new StringBundler(2);
3725
3726 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3727
3728 query.append(_FINDER_COLUMN_CATEGORYID_CATEGORYID_2);
3729
3730 String sql = query.toString();
3731
3732 Session session = null;
3733
3734 try {
3735 session = openSession();
3736
3737 Query q = session.createQuery(sql);
3738
3739 QueryPos qPos = QueryPos.getInstance(q);
3740
3741 qPos.add(categoryId);
3742
3743 count = (Long)q.uniqueResult();
3744 }
3745 catch (Exception e) {
3746 throw processException(e);
3747 }
3748 finally {
3749 if (count == null) {
3750 count = Long.valueOf(0);
3751 }
3752
3753 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CATEGORYID,
3754 finderArgs, count);
3755
3756 closeSession(session);
3757 }
3758 }
3759
3760 return count.intValue();
3761 }
3762
3763 public int countByThreadId(long threadId) throws SystemException {
3764 Object[] finderArgs = new Object[] { threadId };
3765
3766 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
3767 finderArgs, this);
3768
3769 if (count == null) {
3770 StringBundler query = new StringBundler(2);
3771
3772 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3773
3774 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3775
3776 String sql = query.toString();
3777
3778 Session session = null;
3779
3780 try {
3781 session = openSession();
3782
3783 Query q = session.createQuery(sql);
3784
3785 QueryPos qPos = QueryPos.getInstance(q);
3786
3787 qPos.add(threadId);
3788
3789 count = (Long)q.uniqueResult();
3790 }
3791 catch (Exception e) {
3792 throw processException(e);
3793 }
3794 finally {
3795 if (count == null) {
3796 count = Long.valueOf(0);
3797 }
3798
3799 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
3800 finderArgs, count);
3801
3802 closeSession(session);
3803 }
3804 }
3805
3806 return count.intValue();
3807 }
3808
3809 public int countByThreadReplies(long threadId) throws SystemException {
3810 Object[] finderArgs = new Object[] { threadId };
3811
3812 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
3813 finderArgs, this);
3814
3815 if (count == null) {
3816 StringBundler query = new StringBundler(2);
3817
3818 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3819
3820 query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3821
3822 String sql = query.toString();
3823
3824 Session session = null;
3825
3826 try {
3827 session = openSession();
3828
3829 Query q = session.createQuery(sql);
3830
3831 QueryPos qPos = QueryPos.getInstance(q);
3832
3833 qPos.add(threadId);
3834
3835 count = (Long)q.uniqueResult();
3836 }
3837 catch (Exception e) {
3838 throw processException(e);
3839 }
3840 finally {
3841 if (count == null) {
3842 count = Long.valueOf(0);
3843 }
3844
3845 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
3846 finderArgs, count);
3847
3848 closeSession(session);
3849 }
3850 }
3851
3852 return count.intValue();
3853 }
3854
3855 public int countByG_U(long groupId, long userId) throws SystemException {
3856 Object[] finderArgs = new Object[] { groupId, userId };
3857
3858 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
3859 finderArgs, this);
3860
3861 if (count == null) {
3862 StringBundler query = new StringBundler(3);
3863
3864 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3865
3866 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
3867
3868 query.append(_FINDER_COLUMN_G_U_USERID_2);
3869
3870 String sql = query.toString();
3871
3872 Session session = null;
3873
3874 try {
3875 session = openSession();
3876
3877 Query q = session.createQuery(sql);
3878
3879 QueryPos qPos = QueryPos.getInstance(q);
3880
3881 qPos.add(groupId);
3882
3883 qPos.add(userId);
3884
3885 count = (Long)q.uniqueResult();
3886 }
3887 catch (Exception e) {
3888 throw processException(e);
3889 }
3890 finally {
3891 if (count == null) {
3892 count = Long.valueOf(0);
3893 }
3894
3895 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
3896 count);
3897
3898 closeSession(session);
3899 }
3900 }
3901
3902 return count.intValue();
3903 }
3904
3905 public int countByC_C(long classNameId, long classPK)
3906 throws SystemException {
3907 Object[] finderArgs = new Object[] { classNameId, classPK };
3908
3909 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
3910 finderArgs, this);
3911
3912 if (count == null) {
3913 StringBundler query = new StringBundler(3);
3914
3915 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3916
3917 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3918
3919 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3920
3921 String sql = query.toString();
3922
3923 Session session = null;
3924
3925 try {
3926 session = openSession();
3927
3928 Query q = session.createQuery(sql);
3929
3930 QueryPos qPos = QueryPos.getInstance(q);
3931
3932 qPos.add(classNameId);
3933
3934 qPos.add(classPK);
3935
3936 count = (Long)q.uniqueResult();
3937 }
3938 catch (Exception e) {
3939 throw processException(e);
3940 }
3941 finally {
3942 if (count == null) {
3943 count = Long.valueOf(0);
3944 }
3945
3946 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
3947 count);
3948
3949 closeSession(session);
3950 }
3951 }
3952
3953 return count.intValue();
3954 }
3955
3956 public int countByC_T(long categoryId, long threadId)
3957 throws SystemException {
3958 Object[] finderArgs = new Object[] { categoryId, threadId };
3959
3960 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_T,
3961 finderArgs, this);
3962
3963 if (count == null) {
3964 StringBundler query = new StringBundler(3);
3965
3966 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3967
3968 query.append(_FINDER_COLUMN_C_T_CATEGORYID_2);
3969
3970 query.append(_FINDER_COLUMN_C_T_THREADID_2);
3971
3972 String sql = query.toString();
3973
3974 Session session = null;
3975
3976 try {
3977 session = openSession();
3978
3979 Query q = session.createQuery(sql);
3980
3981 QueryPos qPos = QueryPos.getInstance(q);
3982
3983 qPos.add(categoryId);
3984
3985 qPos.add(threadId);
3986
3987 count = (Long)q.uniqueResult();
3988 }
3989 catch (Exception e) {
3990 throw processException(e);
3991 }
3992 finally {
3993 if (count == null) {
3994 count = Long.valueOf(0);
3995 }
3996
3997 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_T, finderArgs,
3998 count);
3999
4000 closeSession(session);
4001 }
4002 }
4003
4004 return count.intValue();
4005 }
4006
4007 public int countByT_P(long threadId, long parentMessageId)
4008 throws SystemException {
4009 Object[] finderArgs = new Object[] { threadId, parentMessageId };
4010
4011 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_P,
4012 finderArgs, this);
4013
4014 if (count == null) {
4015 StringBundler query = new StringBundler(3);
4016
4017 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4018
4019 query.append(_FINDER_COLUMN_T_P_THREADID_2);
4020
4021 query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
4022
4023 String sql = query.toString();
4024
4025 Session session = null;
4026
4027 try {
4028 session = openSession();
4029
4030 Query q = session.createQuery(sql);
4031
4032 QueryPos qPos = QueryPos.getInstance(q);
4033
4034 qPos.add(threadId);
4035
4036 qPos.add(parentMessageId);
4037
4038 count = (Long)q.uniqueResult();
4039 }
4040 catch (Exception e) {
4041 throw processException(e);
4042 }
4043 finally {
4044 if (count == null) {
4045 count = Long.valueOf(0);
4046 }
4047
4048 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_P, finderArgs,
4049 count);
4050
4051 closeSession(session);
4052 }
4053 }
4054
4055 return count.intValue();
4056 }
4057
4058 public int countAll() throws SystemException {
4059 Object[] finderArgs = new Object[0];
4060
4061 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4062 finderArgs, this);
4063
4064 if (count == null) {
4065 Session session = null;
4066
4067 try {
4068 session = openSession();
4069
4070 Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
4071
4072 count = (Long)q.uniqueResult();
4073 }
4074 catch (Exception e) {
4075 throw processException(e);
4076 }
4077 finally {
4078 if (count == null) {
4079 count = Long.valueOf(0);
4080 }
4081
4082 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
4083 count);
4084
4085 closeSession(session);
4086 }
4087 }
4088
4089 return count.intValue();
4090 }
4091
4092 public void afterPropertiesSet() {
4093 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4094 com.liferay.portal.util.PropsUtil.get(
4095 "value.object.listener.com.liferay.portlet.messageboards.model.MBMessage")));
4096
4097 if (listenerClassNames.length > 0) {
4098 try {
4099 List<ModelListener<MBMessage>> listenersList = new ArrayList<ModelListener<MBMessage>>();
4100
4101 for (String listenerClassName : listenerClassNames) {
4102 listenersList.add((ModelListener<MBMessage>)InstanceFactory.newInstance(
4103 listenerClassName));
4104 }
4105
4106 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4107 }
4108 catch (Exception e) {
4109 _log.error(e);
4110 }
4111 }
4112 }
4113
4114 public void destroy() {
4115 EntityCacheUtil.removeCache(MBMessageImpl.class.getName());
4116 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4117 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
4118 }
4119
4120 @BeanReference(type = MBBanPersistence.class)
4121 protected MBBanPersistence mbBanPersistence;
4122 @BeanReference(type = MBCategoryPersistence.class)
4123 protected MBCategoryPersistence mbCategoryPersistence;
4124 @BeanReference(type = MBDiscussionPersistence.class)
4125 protected MBDiscussionPersistence mbDiscussionPersistence;
4126 @BeanReference(type = MBMailingListPersistence.class)
4127 protected MBMailingListPersistence mbMailingListPersistence;
4128 @BeanReference(type = MBMessagePersistence.class)
4129 protected MBMessagePersistence mbMessagePersistence;
4130 @BeanReference(type = MBMessageFlagPersistence.class)
4131 protected MBMessageFlagPersistence mbMessageFlagPersistence;
4132 @BeanReference(type = MBStatsUserPersistence.class)
4133 protected MBStatsUserPersistence mbStatsUserPersistence;
4134 @BeanReference(type = MBThreadPersistence.class)
4135 protected MBThreadPersistence mbThreadPersistence;
4136 @BeanReference(type = CompanyPersistence.class)
4137 protected CompanyPersistence companyPersistence;
4138 @BeanReference(type = GroupPersistence.class)
4139 protected GroupPersistence groupPersistence;
4140 @BeanReference(type = LockPersistence.class)
4141 protected LockPersistence lockPersistence;
4142 @BeanReference(type = PortletPreferencesPersistence.class)
4143 protected PortletPreferencesPersistence portletPreferencesPersistence;
4144 @BeanReference(type = ResourcePersistence.class)
4145 protected ResourcePersistence resourcePersistence;
4146 @BeanReference(type = SubscriptionPersistence.class)
4147 protected SubscriptionPersistence subscriptionPersistence;
4148 @BeanReference(type = UserPersistence.class)
4149 protected UserPersistence userPersistence;
4150 @BeanReference(type = BlogsEntryPersistence.class)
4151 protected BlogsEntryPersistence blogsEntryPersistence;
4152 @BeanReference(type = RatingsStatsPersistence.class)
4153 protected RatingsStatsPersistence ratingsStatsPersistence;
4154 @BeanReference(type = SocialActivityPersistence.class)
4155 protected SocialActivityPersistence socialActivityPersistence;
4156 @BeanReference(type = TagsAssetPersistence.class)
4157 protected TagsAssetPersistence tagsAssetPersistence;
4158 @BeanReference(type = TagsEntryPersistence.class)
4159 protected TagsEntryPersistence tagsEntryPersistence;
4160 private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
4161 private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
4162 private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
4163 private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
4164 private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
4165 private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
4166 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?)";
4167 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
4168 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
4169 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?) AND ";
4170 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
4171 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ?";
4172 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ?";
4173 private static final String _FINDER_COLUMN_CATEGORYID_CATEGORYID_2 = "mbMessage.categoryId = ?";
4174 private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
4175 private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
4176 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
4177 private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ?";
4178 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
4179 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
4180 private static final String _FINDER_COLUMN_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
4181 private static final String _FINDER_COLUMN_C_T_THREADID_2 = "mbMessage.threadId = ?";
4182 private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
4183 private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
4184 private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
4185 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
4186 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
4187 private static Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
4188}