001
014
015 package com.liferay.portlet.messageboards.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.BatchSessionUtil;
039 import com.liferay.portal.service.persistence.ResourcePersistence;
040 import com.liferay.portal.service.persistence.UserPersistence;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.messageboards.NoSuchThreadFlagException;
044 import com.liferay.portlet.messageboards.model.MBThreadFlag;
045 import com.liferay.portlet.messageboards.model.impl.MBThreadFlagImpl;
046 import com.liferay.portlet.messageboards.model.impl.MBThreadFlagModelImpl;
047
048 import java.io.Serializable;
049
050 import java.util.ArrayList;
051 import java.util.Collections;
052 import java.util.List;
053
054
066 public class MBThreadFlagPersistenceImpl extends BasePersistenceImpl<MBThreadFlag>
067 implements MBThreadFlagPersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = MBThreadFlagImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
079 MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
080 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
081 new String[] {
082 Long.class.getName(),
083
084 "java.lang.Integer", "java.lang.Integer",
085 "com.liferay.portal.kernel.util.OrderByComparator"
086 });
087 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
088 new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
089 MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
091 new String[] { Long.class.getName() },
092 MBThreadFlagModelImpl.USERID_COLUMN_BITMASK);
093 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
094 MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
096 new String[] { Long.class.getName() });
097 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
098 MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
099 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
100 new String[] {
101 Long.class.getName(),
102
103 "java.lang.Integer", "java.lang.Integer",
104 "com.liferay.portal.kernel.util.OrderByComparator"
105 });
106 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
107 new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
108 MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
109 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
110 new String[] { Long.class.getName() },
111 MBThreadFlagModelImpl.THREADID_COLUMN_BITMASK);
112 public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
113 MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
114 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
115 new String[] { Long.class.getName() });
116 public static final FinderPath FINDER_PATH_FETCH_BY_U_T = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
117 MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
118 FINDER_CLASS_NAME_ENTITY, "fetchByU_T",
119 new String[] { Long.class.getName(), Long.class.getName() },
120 MBThreadFlagModelImpl.USERID_COLUMN_BITMASK |
121 MBThreadFlagModelImpl.THREADID_COLUMN_BITMASK);
122 public static final FinderPath FINDER_PATH_COUNT_BY_U_T = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
123 MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
124 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_T",
125 new String[] { Long.class.getName(), Long.class.getName() });
126 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
127 MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
128 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
129 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
130 MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
131 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
132 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
133 MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
134 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
135
136
141 public void cacheResult(MBThreadFlag mbThreadFlag) {
142 EntityCacheUtil.putResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
143 MBThreadFlagImpl.class, mbThreadFlag.getPrimaryKey(), mbThreadFlag);
144
145 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
146 new Object[] {
147 Long.valueOf(mbThreadFlag.getUserId()),
148 Long.valueOf(mbThreadFlag.getThreadId())
149 }, mbThreadFlag);
150
151 mbThreadFlag.resetOriginalValues();
152 }
153
154
159 public void cacheResult(List<MBThreadFlag> mbThreadFlags) {
160 for (MBThreadFlag mbThreadFlag : mbThreadFlags) {
161 if (EntityCacheUtil.getResult(
162 MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
163 MBThreadFlagImpl.class, mbThreadFlag.getPrimaryKey()) == null) {
164 cacheResult(mbThreadFlag);
165 }
166 else {
167 mbThreadFlag.resetOriginalValues();
168 }
169 }
170 }
171
172
179 @Override
180 public void clearCache() {
181 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
182 CacheRegistryUtil.clear(MBThreadFlagImpl.class.getName());
183 }
184
185 EntityCacheUtil.clearCache(MBThreadFlagImpl.class.getName());
186
187 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
188 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
189 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
190 }
191
192
199 @Override
200 public void clearCache(MBThreadFlag mbThreadFlag) {
201 EntityCacheUtil.removeResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
202 MBThreadFlagImpl.class, mbThreadFlag.getPrimaryKey());
203
204 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
205 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
206
207 clearUniqueFindersCache(mbThreadFlag);
208 }
209
210 @Override
211 public void clearCache(List<MBThreadFlag> mbThreadFlags) {
212 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
213 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
214
215 for (MBThreadFlag mbThreadFlag : mbThreadFlags) {
216 EntityCacheUtil.removeResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
217 MBThreadFlagImpl.class, mbThreadFlag.getPrimaryKey());
218
219 clearUniqueFindersCache(mbThreadFlag);
220 }
221 }
222
223 protected void cacheUniqueFindersCache(MBThreadFlag mbThreadFlag) {
224 if (mbThreadFlag.isNew()) {
225 Object[] args = new Object[] {
226 Long.valueOf(mbThreadFlag.getUserId()),
227 Long.valueOf(mbThreadFlag.getThreadId())
228 };
229
230 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, args,
231 Long.valueOf(1));
232 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T, args,
233 mbThreadFlag);
234 }
235 else {
236 MBThreadFlagModelImpl mbThreadFlagModelImpl = (MBThreadFlagModelImpl)mbThreadFlag;
237
238 if ((mbThreadFlagModelImpl.getColumnBitmask() &
239 FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
240 Object[] args = new Object[] {
241 Long.valueOf(mbThreadFlag.getUserId()),
242 Long.valueOf(mbThreadFlag.getThreadId())
243 };
244
245 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, args,
246 Long.valueOf(1));
247 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T, args,
248 mbThreadFlag);
249 }
250 }
251 }
252
253 protected void clearUniqueFindersCache(MBThreadFlag mbThreadFlag) {
254 MBThreadFlagModelImpl mbThreadFlagModelImpl = (MBThreadFlagModelImpl)mbThreadFlag;
255
256 Object[] args = new Object[] {
257 Long.valueOf(mbThreadFlag.getUserId()),
258 Long.valueOf(mbThreadFlag.getThreadId())
259 };
260
261 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
262 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
263
264 if ((mbThreadFlagModelImpl.getColumnBitmask() &
265 FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
266 args = new Object[] {
267 Long.valueOf(mbThreadFlagModelImpl.getOriginalUserId()),
268 Long.valueOf(mbThreadFlagModelImpl.getOriginalThreadId())
269 };
270
271 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
272 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
273 }
274 }
275
276
282 public MBThreadFlag create(long threadFlagId) {
283 MBThreadFlag mbThreadFlag = new MBThreadFlagImpl();
284
285 mbThreadFlag.setNew(true);
286 mbThreadFlag.setPrimaryKey(threadFlagId);
287
288 return mbThreadFlag;
289 }
290
291
299 public MBThreadFlag remove(long threadFlagId)
300 throws NoSuchThreadFlagException, SystemException {
301 return remove(Long.valueOf(threadFlagId));
302 }
303
304
312 @Override
313 public MBThreadFlag remove(Serializable primaryKey)
314 throws NoSuchThreadFlagException, SystemException {
315 Session session = null;
316
317 try {
318 session = openSession();
319
320 MBThreadFlag mbThreadFlag = (MBThreadFlag)session.get(MBThreadFlagImpl.class,
321 primaryKey);
322
323 if (mbThreadFlag == null) {
324 if (_log.isWarnEnabled()) {
325 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
326 }
327
328 throw new NoSuchThreadFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
329 primaryKey);
330 }
331
332 return remove(mbThreadFlag);
333 }
334 catch (NoSuchThreadFlagException nsee) {
335 throw nsee;
336 }
337 catch (Exception e) {
338 throw processException(e);
339 }
340 finally {
341 closeSession(session);
342 }
343 }
344
345 @Override
346 protected MBThreadFlag removeImpl(MBThreadFlag mbThreadFlag)
347 throws SystemException {
348 mbThreadFlag = toUnwrappedModel(mbThreadFlag);
349
350 Session session = null;
351
352 try {
353 session = openSession();
354
355 BatchSessionUtil.delete(session, mbThreadFlag);
356 }
357 catch (Exception e) {
358 throw processException(e);
359 }
360 finally {
361 closeSession(session);
362 }
363
364 clearCache(mbThreadFlag);
365
366 return mbThreadFlag;
367 }
368
369 @Override
370 public MBThreadFlag updateImpl(
371 com.liferay.portlet.messageboards.model.MBThreadFlag mbThreadFlag,
372 boolean merge) throws SystemException {
373 mbThreadFlag = toUnwrappedModel(mbThreadFlag);
374
375 boolean isNew = mbThreadFlag.isNew();
376
377 MBThreadFlagModelImpl mbThreadFlagModelImpl = (MBThreadFlagModelImpl)mbThreadFlag;
378
379 Session session = null;
380
381 try {
382 session = openSession();
383
384 BatchSessionUtil.update(session, mbThreadFlag, merge);
385
386 mbThreadFlag.setNew(false);
387 }
388 catch (Exception e) {
389 throw processException(e);
390 }
391 finally {
392 closeSession(session);
393 }
394
395 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
396
397 if (isNew || !MBThreadFlagModelImpl.COLUMN_BITMASK_ENABLED) {
398 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
399 }
400
401 else {
402 if ((mbThreadFlagModelImpl.getColumnBitmask() &
403 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
404 Object[] args = new Object[] {
405 Long.valueOf(mbThreadFlagModelImpl.getOriginalUserId())
406 };
407
408 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
409 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
410 args);
411
412 args = new Object[] {
413 Long.valueOf(mbThreadFlagModelImpl.getUserId())
414 };
415
416 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
417 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
418 args);
419 }
420
421 if ((mbThreadFlagModelImpl.getColumnBitmask() &
422 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
423 Object[] args = new Object[] {
424 Long.valueOf(mbThreadFlagModelImpl.getOriginalThreadId())
425 };
426
427 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
428 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
429 args);
430
431 args = new Object[] {
432 Long.valueOf(mbThreadFlagModelImpl.getThreadId())
433 };
434
435 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
436 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
437 args);
438 }
439 }
440
441 EntityCacheUtil.putResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
442 MBThreadFlagImpl.class, mbThreadFlag.getPrimaryKey(), mbThreadFlag);
443
444 clearUniqueFindersCache(mbThreadFlag);
445 cacheUniqueFindersCache(mbThreadFlag);
446
447 return mbThreadFlag;
448 }
449
450 protected MBThreadFlag toUnwrappedModel(MBThreadFlag mbThreadFlag) {
451 if (mbThreadFlag instanceof MBThreadFlagImpl) {
452 return mbThreadFlag;
453 }
454
455 MBThreadFlagImpl mbThreadFlagImpl = new MBThreadFlagImpl();
456
457 mbThreadFlagImpl.setNew(mbThreadFlag.isNew());
458 mbThreadFlagImpl.setPrimaryKey(mbThreadFlag.getPrimaryKey());
459
460 mbThreadFlagImpl.setThreadFlagId(mbThreadFlag.getThreadFlagId());
461 mbThreadFlagImpl.setUserId(mbThreadFlag.getUserId());
462 mbThreadFlagImpl.setModifiedDate(mbThreadFlag.getModifiedDate());
463 mbThreadFlagImpl.setThreadId(mbThreadFlag.getThreadId());
464
465 return mbThreadFlagImpl;
466 }
467
468
476 @Override
477 public MBThreadFlag findByPrimaryKey(Serializable primaryKey)
478 throws NoSuchModelException, SystemException {
479 return findByPrimaryKey(((Long)primaryKey).longValue());
480 }
481
482
490 public MBThreadFlag findByPrimaryKey(long threadFlagId)
491 throws NoSuchThreadFlagException, SystemException {
492 MBThreadFlag mbThreadFlag = fetchByPrimaryKey(threadFlagId);
493
494 if (mbThreadFlag == null) {
495 if (_log.isWarnEnabled()) {
496 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + threadFlagId);
497 }
498
499 throw new NoSuchThreadFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
500 threadFlagId);
501 }
502
503 return mbThreadFlag;
504 }
505
506
513 @Override
514 public MBThreadFlag fetchByPrimaryKey(Serializable primaryKey)
515 throws SystemException {
516 return fetchByPrimaryKey(((Long)primaryKey).longValue());
517 }
518
519
526 public MBThreadFlag fetchByPrimaryKey(long threadFlagId)
527 throws SystemException {
528 MBThreadFlag mbThreadFlag = (MBThreadFlag)EntityCacheUtil.getResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
529 MBThreadFlagImpl.class, threadFlagId);
530
531 if (mbThreadFlag == _nullMBThreadFlag) {
532 return null;
533 }
534
535 if (mbThreadFlag == null) {
536 Session session = null;
537
538 boolean hasException = false;
539
540 try {
541 session = openSession();
542
543 mbThreadFlag = (MBThreadFlag)session.get(MBThreadFlagImpl.class,
544 Long.valueOf(threadFlagId));
545 }
546 catch (Exception e) {
547 hasException = true;
548
549 throw processException(e);
550 }
551 finally {
552 if (mbThreadFlag != null) {
553 cacheResult(mbThreadFlag);
554 }
555 else if (!hasException) {
556 EntityCacheUtil.putResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
557 MBThreadFlagImpl.class, threadFlagId, _nullMBThreadFlag);
558 }
559
560 closeSession(session);
561 }
562 }
563
564 return mbThreadFlag;
565 }
566
567
574 public List<MBThreadFlag> findByUserId(long userId)
575 throws SystemException {
576 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
577 }
578
579
592 public List<MBThreadFlag> findByUserId(long userId, int start, int end)
593 throws SystemException {
594 return findByUserId(userId, start, end, null);
595 }
596
597
611 public List<MBThreadFlag> findByUserId(long userId, int start, int end,
612 OrderByComparator orderByComparator) throws SystemException {
613 FinderPath finderPath = null;
614 Object[] finderArgs = null;
615
616 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
617 (orderByComparator == null)) {
618 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
619 finderArgs = new Object[] { userId };
620 }
621 else {
622 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
623 finderArgs = new Object[] { userId, start, end, orderByComparator };
624 }
625
626 List<MBThreadFlag> list = (List<MBThreadFlag>)FinderCacheUtil.getResult(finderPath,
627 finderArgs, this);
628
629 if ((list != null) && !list.isEmpty()) {
630 for (MBThreadFlag mbThreadFlag : list) {
631 if ((userId != mbThreadFlag.getUserId())) {
632 list = null;
633
634 break;
635 }
636 }
637 }
638
639 if (list == null) {
640 StringBundler query = null;
641
642 if (orderByComparator != null) {
643 query = new StringBundler(3 +
644 (orderByComparator.getOrderByFields().length * 3));
645 }
646 else {
647 query = new StringBundler(2);
648 }
649
650 query.append(_SQL_SELECT_MBTHREADFLAG_WHERE);
651
652 query.append(_FINDER_COLUMN_USERID_USERID_2);
653
654 if (orderByComparator != null) {
655 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
656 orderByComparator);
657 }
658
659 String sql = query.toString();
660
661 Session session = null;
662
663 try {
664 session = openSession();
665
666 Query q = session.createQuery(sql);
667
668 QueryPos qPos = QueryPos.getInstance(q);
669
670 qPos.add(userId);
671
672 list = (List<MBThreadFlag>)QueryUtil.list(q, getDialect(),
673 start, end);
674 }
675 catch (Exception e) {
676 throw processException(e);
677 }
678 finally {
679 if (list == null) {
680 FinderCacheUtil.removeResult(finderPath, finderArgs);
681 }
682 else {
683 cacheResult(list);
684
685 FinderCacheUtil.putResult(finderPath, finderArgs, list);
686 }
687
688 closeSession(session);
689 }
690 }
691
692 return list;
693 }
694
695
704 public MBThreadFlag findByUserId_First(long userId,
705 OrderByComparator orderByComparator)
706 throws NoSuchThreadFlagException, SystemException {
707 MBThreadFlag mbThreadFlag = fetchByUserId_First(userId,
708 orderByComparator);
709
710 if (mbThreadFlag != null) {
711 return mbThreadFlag;
712 }
713
714 StringBundler msg = new StringBundler(4);
715
716 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
717
718 msg.append("userId=");
719 msg.append(userId);
720
721 msg.append(StringPool.CLOSE_CURLY_BRACE);
722
723 throw new NoSuchThreadFlagException(msg.toString());
724 }
725
726
734 public MBThreadFlag fetchByUserId_First(long userId,
735 OrderByComparator orderByComparator) throws SystemException {
736 List<MBThreadFlag> list = findByUserId(userId, 0, 1, orderByComparator);
737
738 if (!list.isEmpty()) {
739 return list.get(0);
740 }
741
742 return null;
743 }
744
745
754 public MBThreadFlag findByUserId_Last(long userId,
755 OrderByComparator orderByComparator)
756 throws NoSuchThreadFlagException, SystemException {
757 MBThreadFlag mbThreadFlag = fetchByUserId_Last(userId, orderByComparator);
758
759 if (mbThreadFlag != null) {
760 return mbThreadFlag;
761 }
762
763 StringBundler msg = new StringBundler(4);
764
765 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
766
767 msg.append("userId=");
768 msg.append(userId);
769
770 msg.append(StringPool.CLOSE_CURLY_BRACE);
771
772 throw new NoSuchThreadFlagException(msg.toString());
773 }
774
775
783 public MBThreadFlag fetchByUserId_Last(long userId,
784 OrderByComparator orderByComparator) throws SystemException {
785 int count = countByUserId(userId);
786
787 List<MBThreadFlag> list = findByUserId(userId, count - 1, count,
788 orderByComparator);
789
790 if (!list.isEmpty()) {
791 return list.get(0);
792 }
793
794 return null;
795 }
796
797
807 public MBThreadFlag[] findByUserId_PrevAndNext(long threadFlagId,
808 long userId, OrderByComparator orderByComparator)
809 throws NoSuchThreadFlagException, SystemException {
810 MBThreadFlag mbThreadFlag = findByPrimaryKey(threadFlagId);
811
812 Session session = null;
813
814 try {
815 session = openSession();
816
817 MBThreadFlag[] array = new MBThreadFlagImpl[3];
818
819 array[0] = getByUserId_PrevAndNext(session, mbThreadFlag, userId,
820 orderByComparator, true);
821
822 array[1] = mbThreadFlag;
823
824 array[2] = getByUserId_PrevAndNext(session, mbThreadFlag, userId,
825 orderByComparator, false);
826
827 return array;
828 }
829 catch (Exception e) {
830 throw processException(e);
831 }
832 finally {
833 closeSession(session);
834 }
835 }
836
837 protected MBThreadFlag getByUserId_PrevAndNext(Session session,
838 MBThreadFlag mbThreadFlag, long userId,
839 OrderByComparator orderByComparator, boolean previous) {
840 StringBundler query = null;
841
842 if (orderByComparator != null) {
843 query = new StringBundler(6 +
844 (orderByComparator.getOrderByFields().length * 6));
845 }
846 else {
847 query = new StringBundler(3);
848 }
849
850 query.append(_SQL_SELECT_MBTHREADFLAG_WHERE);
851
852 query.append(_FINDER_COLUMN_USERID_USERID_2);
853
854 if (orderByComparator != null) {
855 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
856
857 if (orderByConditionFields.length > 0) {
858 query.append(WHERE_AND);
859 }
860
861 for (int i = 0; i < orderByConditionFields.length; i++) {
862 query.append(_ORDER_BY_ENTITY_ALIAS);
863 query.append(orderByConditionFields[i]);
864
865 if ((i + 1) < orderByConditionFields.length) {
866 if (orderByComparator.isAscending() ^ previous) {
867 query.append(WHERE_GREATER_THAN_HAS_NEXT);
868 }
869 else {
870 query.append(WHERE_LESSER_THAN_HAS_NEXT);
871 }
872 }
873 else {
874 if (orderByComparator.isAscending() ^ previous) {
875 query.append(WHERE_GREATER_THAN);
876 }
877 else {
878 query.append(WHERE_LESSER_THAN);
879 }
880 }
881 }
882
883 query.append(ORDER_BY_CLAUSE);
884
885 String[] orderByFields = orderByComparator.getOrderByFields();
886
887 for (int i = 0; i < orderByFields.length; i++) {
888 query.append(_ORDER_BY_ENTITY_ALIAS);
889 query.append(orderByFields[i]);
890
891 if ((i + 1) < orderByFields.length) {
892 if (orderByComparator.isAscending() ^ previous) {
893 query.append(ORDER_BY_ASC_HAS_NEXT);
894 }
895 else {
896 query.append(ORDER_BY_DESC_HAS_NEXT);
897 }
898 }
899 else {
900 if (orderByComparator.isAscending() ^ previous) {
901 query.append(ORDER_BY_ASC);
902 }
903 else {
904 query.append(ORDER_BY_DESC);
905 }
906 }
907 }
908 }
909
910 String sql = query.toString();
911
912 Query q = session.createQuery(sql);
913
914 q.setFirstResult(0);
915 q.setMaxResults(2);
916
917 QueryPos qPos = QueryPos.getInstance(q);
918
919 qPos.add(userId);
920
921 if (orderByComparator != null) {
922 Object[] values = orderByComparator.getOrderByConditionValues(mbThreadFlag);
923
924 for (Object value : values) {
925 qPos.add(value);
926 }
927 }
928
929 List<MBThreadFlag> list = q.list();
930
931 if (list.size() == 2) {
932 return list.get(1);
933 }
934 else {
935 return null;
936 }
937 }
938
939
946 public List<MBThreadFlag> findByThreadId(long threadId)
947 throws SystemException {
948 return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
949 null);
950 }
951
952
965 public List<MBThreadFlag> findByThreadId(long threadId, int start, int end)
966 throws SystemException {
967 return findByThreadId(threadId, start, end, null);
968 }
969
970
984 public List<MBThreadFlag> findByThreadId(long threadId, int start, int end,
985 OrderByComparator orderByComparator) throws SystemException {
986 FinderPath finderPath = null;
987 Object[] finderArgs = null;
988
989 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
990 (orderByComparator == null)) {
991 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
992 finderArgs = new Object[] { threadId };
993 }
994 else {
995 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
996 finderArgs = new Object[] { threadId, start, end, orderByComparator };
997 }
998
999 List<MBThreadFlag> list = (List<MBThreadFlag>)FinderCacheUtil.getResult(finderPath,
1000 finderArgs, this);
1001
1002 if ((list != null) && !list.isEmpty()) {
1003 for (MBThreadFlag mbThreadFlag : list) {
1004 if ((threadId != mbThreadFlag.getThreadId())) {
1005 list = null;
1006
1007 break;
1008 }
1009 }
1010 }
1011
1012 if (list == null) {
1013 StringBundler query = null;
1014
1015 if (orderByComparator != null) {
1016 query = new StringBundler(3 +
1017 (orderByComparator.getOrderByFields().length * 3));
1018 }
1019 else {
1020 query = new StringBundler(2);
1021 }
1022
1023 query.append(_SQL_SELECT_MBTHREADFLAG_WHERE);
1024
1025 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
1026
1027 if (orderByComparator != null) {
1028 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1029 orderByComparator);
1030 }
1031
1032 String sql = query.toString();
1033
1034 Session session = null;
1035
1036 try {
1037 session = openSession();
1038
1039 Query q = session.createQuery(sql);
1040
1041 QueryPos qPos = QueryPos.getInstance(q);
1042
1043 qPos.add(threadId);
1044
1045 list = (List<MBThreadFlag>)QueryUtil.list(q, getDialect(),
1046 start, end);
1047 }
1048 catch (Exception e) {
1049 throw processException(e);
1050 }
1051 finally {
1052 if (list == null) {
1053 FinderCacheUtil.removeResult(finderPath, finderArgs);
1054 }
1055 else {
1056 cacheResult(list);
1057
1058 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1059 }
1060
1061 closeSession(session);
1062 }
1063 }
1064
1065 return list;
1066 }
1067
1068
1077 public MBThreadFlag findByThreadId_First(long threadId,
1078 OrderByComparator orderByComparator)
1079 throws NoSuchThreadFlagException, SystemException {
1080 MBThreadFlag mbThreadFlag = fetchByThreadId_First(threadId,
1081 orderByComparator);
1082
1083 if (mbThreadFlag != null) {
1084 return mbThreadFlag;
1085 }
1086
1087 StringBundler msg = new StringBundler(4);
1088
1089 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1090
1091 msg.append("threadId=");
1092 msg.append(threadId);
1093
1094 msg.append(StringPool.CLOSE_CURLY_BRACE);
1095
1096 throw new NoSuchThreadFlagException(msg.toString());
1097 }
1098
1099
1107 public MBThreadFlag fetchByThreadId_First(long threadId,
1108 OrderByComparator orderByComparator) throws SystemException {
1109 List<MBThreadFlag> list = findByThreadId(threadId, 0, 1,
1110 orderByComparator);
1111
1112 if (!list.isEmpty()) {
1113 return list.get(0);
1114 }
1115
1116 return null;
1117 }
1118
1119
1128 public MBThreadFlag findByThreadId_Last(long threadId,
1129 OrderByComparator orderByComparator)
1130 throws NoSuchThreadFlagException, SystemException {
1131 MBThreadFlag mbThreadFlag = fetchByThreadId_Last(threadId,
1132 orderByComparator);
1133
1134 if (mbThreadFlag != null) {
1135 return mbThreadFlag;
1136 }
1137
1138 StringBundler msg = new StringBundler(4);
1139
1140 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1141
1142 msg.append("threadId=");
1143 msg.append(threadId);
1144
1145 msg.append(StringPool.CLOSE_CURLY_BRACE);
1146
1147 throw new NoSuchThreadFlagException(msg.toString());
1148 }
1149
1150
1158 public MBThreadFlag fetchByThreadId_Last(long threadId,
1159 OrderByComparator orderByComparator) throws SystemException {
1160 int count = countByThreadId(threadId);
1161
1162 List<MBThreadFlag> list = findByThreadId(threadId, count - 1, count,
1163 orderByComparator);
1164
1165 if (!list.isEmpty()) {
1166 return list.get(0);
1167 }
1168
1169 return null;
1170 }
1171
1172
1182 public MBThreadFlag[] findByThreadId_PrevAndNext(long threadFlagId,
1183 long threadId, OrderByComparator orderByComparator)
1184 throws NoSuchThreadFlagException, SystemException {
1185 MBThreadFlag mbThreadFlag = findByPrimaryKey(threadFlagId);
1186
1187 Session session = null;
1188
1189 try {
1190 session = openSession();
1191
1192 MBThreadFlag[] array = new MBThreadFlagImpl[3];
1193
1194 array[0] = getByThreadId_PrevAndNext(session, mbThreadFlag,
1195 threadId, orderByComparator, true);
1196
1197 array[1] = mbThreadFlag;
1198
1199 array[2] = getByThreadId_PrevAndNext(session, mbThreadFlag,
1200 threadId, orderByComparator, false);
1201
1202 return array;
1203 }
1204 catch (Exception e) {
1205 throw processException(e);
1206 }
1207 finally {
1208 closeSession(session);
1209 }
1210 }
1211
1212 protected MBThreadFlag getByThreadId_PrevAndNext(Session session,
1213 MBThreadFlag mbThreadFlag, long threadId,
1214 OrderByComparator orderByComparator, boolean previous) {
1215 StringBundler query = null;
1216
1217 if (orderByComparator != null) {
1218 query = new StringBundler(6 +
1219 (orderByComparator.getOrderByFields().length * 6));
1220 }
1221 else {
1222 query = new StringBundler(3);
1223 }
1224
1225 query.append(_SQL_SELECT_MBTHREADFLAG_WHERE);
1226
1227 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
1228
1229 if (orderByComparator != null) {
1230 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1231
1232 if (orderByConditionFields.length > 0) {
1233 query.append(WHERE_AND);
1234 }
1235
1236 for (int i = 0; i < orderByConditionFields.length; i++) {
1237 query.append(_ORDER_BY_ENTITY_ALIAS);
1238 query.append(orderByConditionFields[i]);
1239
1240 if ((i + 1) < orderByConditionFields.length) {
1241 if (orderByComparator.isAscending() ^ previous) {
1242 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1243 }
1244 else {
1245 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1246 }
1247 }
1248 else {
1249 if (orderByComparator.isAscending() ^ previous) {
1250 query.append(WHERE_GREATER_THAN);
1251 }
1252 else {
1253 query.append(WHERE_LESSER_THAN);
1254 }
1255 }
1256 }
1257
1258 query.append(ORDER_BY_CLAUSE);
1259
1260 String[] orderByFields = orderByComparator.getOrderByFields();
1261
1262 for (int i = 0; i < orderByFields.length; i++) {
1263 query.append(_ORDER_BY_ENTITY_ALIAS);
1264 query.append(orderByFields[i]);
1265
1266 if ((i + 1) < orderByFields.length) {
1267 if (orderByComparator.isAscending() ^ previous) {
1268 query.append(ORDER_BY_ASC_HAS_NEXT);
1269 }
1270 else {
1271 query.append(ORDER_BY_DESC_HAS_NEXT);
1272 }
1273 }
1274 else {
1275 if (orderByComparator.isAscending() ^ previous) {
1276 query.append(ORDER_BY_ASC);
1277 }
1278 else {
1279 query.append(ORDER_BY_DESC);
1280 }
1281 }
1282 }
1283 }
1284
1285 String sql = query.toString();
1286
1287 Query q = session.createQuery(sql);
1288
1289 q.setFirstResult(0);
1290 q.setMaxResults(2);
1291
1292 QueryPos qPos = QueryPos.getInstance(q);
1293
1294 qPos.add(threadId);
1295
1296 if (orderByComparator != null) {
1297 Object[] values = orderByComparator.getOrderByConditionValues(mbThreadFlag);
1298
1299 for (Object value : values) {
1300 qPos.add(value);
1301 }
1302 }
1303
1304 List<MBThreadFlag> list = q.list();
1305
1306 if (list.size() == 2) {
1307 return list.get(1);
1308 }
1309 else {
1310 return null;
1311 }
1312 }
1313
1314
1323 public MBThreadFlag findByU_T(long userId, long threadId)
1324 throws NoSuchThreadFlagException, SystemException {
1325 MBThreadFlag mbThreadFlag = fetchByU_T(userId, threadId);
1326
1327 if (mbThreadFlag == null) {
1328 StringBundler msg = new StringBundler(6);
1329
1330 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1331
1332 msg.append("userId=");
1333 msg.append(userId);
1334
1335 msg.append(", threadId=");
1336 msg.append(threadId);
1337
1338 msg.append(StringPool.CLOSE_CURLY_BRACE);
1339
1340 if (_log.isWarnEnabled()) {
1341 _log.warn(msg.toString());
1342 }
1343
1344 throw new NoSuchThreadFlagException(msg.toString());
1345 }
1346
1347 return mbThreadFlag;
1348 }
1349
1350
1358 public MBThreadFlag fetchByU_T(long userId, long threadId)
1359 throws SystemException {
1360 return fetchByU_T(userId, threadId, true);
1361 }
1362
1363
1372 public MBThreadFlag fetchByU_T(long userId, long threadId,
1373 boolean retrieveFromCache) throws SystemException {
1374 Object[] finderArgs = new Object[] { userId, threadId };
1375
1376 Object result = null;
1377
1378 if (retrieveFromCache) {
1379 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
1380 finderArgs, this);
1381 }
1382
1383 if (result instanceof MBThreadFlag) {
1384 MBThreadFlag mbThreadFlag = (MBThreadFlag)result;
1385
1386 if ((userId != mbThreadFlag.getUserId()) ||
1387 (threadId != mbThreadFlag.getThreadId())) {
1388 result = null;
1389 }
1390 }
1391
1392 if (result == null) {
1393 StringBundler query = new StringBundler(3);
1394
1395 query.append(_SQL_SELECT_MBTHREADFLAG_WHERE);
1396
1397 query.append(_FINDER_COLUMN_U_T_USERID_2);
1398
1399 query.append(_FINDER_COLUMN_U_T_THREADID_2);
1400
1401 String sql = query.toString();
1402
1403 Session session = null;
1404
1405 try {
1406 session = openSession();
1407
1408 Query q = session.createQuery(sql);
1409
1410 QueryPos qPos = QueryPos.getInstance(q);
1411
1412 qPos.add(userId);
1413
1414 qPos.add(threadId);
1415
1416 List<MBThreadFlag> list = q.list();
1417
1418 result = list;
1419
1420 MBThreadFlag mbThreadFlag = null;
1421
1422 if (list.isEmpty()) {
1423 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
1424 finderArgs, list);
1425 }
1426 else {
1427 mbThreadFlag = list.get(0);
1428
1429 cacheResult(mbThreadFlag);
1430
1431 if ((mbThreadFlag.getUserId() != userId) ||
1432 (mbThreadFlag.getThreadId() != threadId)) {
1433 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
1434 finderArgs, mbThreadFlag);
1435 }
1436 }
1437
1438 return mbThreadFlag;
1439 }
1440 catch (Exception e) {
1441 throw processException(e);
1442 }
1443 finally {
1444 if (result == null) {
1445 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
1446 finderArgs);
1447 }
1448
1449 closeSession(session);
1450 }
1451 }
1452 else {
1453 if (result instanceof List<?>) {
1454 return null;
1455 }
1456 else {
1457 return (MBThreadFlag)result;
1458 }
1459 }
1460 }
1461
1462
1468 public List<MBThreadFlag> findAll() throws SystemException {
1469 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1470 }
1471
1472
1484 public List<MBThreadFlag> findAll(int start, int end)
1485 throws SystemException {
1486 return findAll(start, end, null);
1487 }
1488
1489
1502 public List<MBThreadFlag> findAll(int start, int end,
1503 OrderByComparator orderByComparator) throws SystemException {
1504 FinderPath finderPath = null;
1505 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1506
1507 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1508 (orderByComparator == null)) {
1509 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1510 finderArgs = FINDER_ARGS_EMPTY;
1511 }
1512 else {
1513 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1514 finderArgs = new Object[] { start, end, orderByComparator };
1515 }
1516
1517 List<MBThreadFlag> list = (List<MBThreadFlag>)FinderCacheUtil.getResult(finderPath,
1518 finderArgs, this);
1519
1520 if (list == null) {
1521 StringBundler query = null;
1522 String sql = null;
1523
1524 if (orderByComparator != null) {
1525 query = new StringBundler(2 +
1526 (orderByComparator.getOrderByFields().length * 3));
1527
1528 query.append(_SQL_SELECT_MBTHREADFLAG);
1529
1530 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1531 orderByComparator);
1532
1533 sql = query.toString();
1534 }
1535 else {
1536 sql = _SQL_SELECT_MBTHREADFLAG;
1537 }
1538
1539 Session session = null;
1540
1541 try {
1542 session = openSession();
1543
1544 Query q = session.createQuery(sql);
1545
1546 if (orderByComparator == null) {
1547 list = (List<MBThreadFlag>)QueryUtil.list(q, getDialect(),
1548 start, end, false);
1549
1550 Collections.sort(list);
1551 }
1552 else {
1553 list = (List<MBThreadFlag>)QueryUtil.list(q, getDialect(),
1554 start, end);
1555 }
1556 }
1557 catch (Exception e) {
1558 throw processException(e);
1559 }
1560 finally {
1561 if (list == null) {
1562 FinderCacheUtil.removeResult(finderPath, finderArgs);
1563 }
1564 else {
1565 cacheResult(list);
1566
1567 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1568 }
1569
1570 closeSession(session);
1571 }
1572 }
1573
1574 return list;
1575 }
1576
1577
1583 public void removeByUserId(long userId) throws SystemException {
1584 for (MBThreadFlag mbThreadFlag : findByUserId(userId)) {
1585 remove(mbThreadFlag);
1586 }
1587 }
1588
1589
1595 public void removeByThreadId(long threadId) throws SystemException {
1596 for (MBThreadFlag mbThreadFlag : findByThreadId(threadId)) {
1597 remove(mbThreadFlag);
1598 }
1599 }
1600
1601
1609 public MBThreadFlag removeByU_T(long userId, long threadId)
1610 throws NoSuchThreadFlagException, SystemException {
1611 MBThreadFlag mbThreadFlag = findByU_T(userId, threadId);
1612
1613 return remove(mbThreadFlag);
1614 }
1615
1616
1621 public void removeAll() throws SystemException {
1622 for (MBThreadFlag mbThreadFlag : findAll()) {
1623 remove(mbThreadFlag);
1624 }
1625 }
1626
1627
1634 public int countByUserId(long userId) throws SystemException {
1635 Object[] finderArgs = new Object[] { userId };
1636
1637 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1638 finderArgs, this);
1639
1640 if (count == null) {
1641 StringBundler query = new StringBundler(2);
1642
1643 query.append(_SQL_COUNT_MBTHREADFLAG_WHERE);
1644
1645 query.append(_FINDER_COLUMN_USERID_USERID_2);
1646
1647 String sql = query.toString();
1648
1649 Session session = null;
1650
1651 try {
1652 session = openSession();
1653
1654 Query q = session.createQuery(sql);
1655
1656 QueryPos qPos = QueryPos.getInstance(q);
1657
1658 qPos.add(userId);
1659
1660 count = (Long)q.uniqueResult();
1661 }
1662 catch (Exception e) {
1663 throw processException(e);
1664 }
1665 finally {
1666 if (count == null) {
1667 count = Long.valueOf(0);
1668 }
1669
1670 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1671 finderArgs, count);
1672
1673 closeSession(session);
1674 }
1675 }
1676
1677 return count.intValue();
1678 }
1679
1680
1687 public int countByThreadId(long threadId) throws SystemException {
1688 Object[] finderArgs = new Object[] { threadId };
1689
1690 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
1691 finderArgs, this);
1692
1693 if (count == null) {
1694 StringBundler query = new StringBundler(2);
1695
1696 query.append(_SQL_COUNT_MBTHREADFLAG_WHERE);
1697
1698 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
1699
1700 String sql = query.toString();
1701
1702 Session session = null;
1703
1704 try {
1705 session = openSession();
1706
1707 Query q = session.createQuery(sql);
1708
1709 QueryPos qPos = QueryPos.getInstance(q);
1710
1711 qPos.add(threadId);
1712
1713 count = (Long)q.uniqueResult();
1714 }
1715 catch (Exception e) {
1716 throw processException(e);
1717 }
1718 finally {
1719 if (count == null) {
1720 count = Long.valueOf(0);
1721 }
1722
1723 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
1724 finderArgs, count);
1725
1726 closeSession(session);
1727 }
1728 }
1729
1730 return count.intValue();
1731 }
1732
1733
1741 public int countByU_T(long userId, long threadId) throws SystemException {
1742 Object[] finderArgs = new Object[] { userId, threadId };
1743
1744 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T,
1745 finderArgs, this);
1746
1747 if (count == null) {
1748 StringBundler query = new StringBundler(3);
1749
1750 query.append(_SQL_COUNT_MBTHREADFLAG_WHERE);
1751
1752 query.append(_FINDER_COLUMN_U_T_USERID_2);
1753
1754 query.append(_FINDER_COLUMN_U_T_THREADID_2);
1755
1756 String sql = query.toString();
1757
1758 Session session = null;
1759
1760 try {
1761 session = openSession();
1762
1763 Query q = session.createQuery(sql);
1764
1765 QueryPos qPos = QueryPos.getInstance(q);
1766
1767 qPos.add(userId);
1768
1769 qPos.add(threadId);
1770
1771 count = (Long)q.uniqueResult();
1772 }
1773 catch (Exception e) {
1774 throw processException(e);
1775 }
1776 finally {
1777 if (count == null) {
1778 count = Long.valueOf(0);
1779 }
1780
1781 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, finderArgs,
1782 count);
1783
1784 closeSession(session);
1785 }
1786 }
1787
1788 return count.intValue();
1789 }
1790
1791
1797 public int countAll() throws SystemException {
1798 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1799 FINDER_ARGS_EMPTY, this);
1800
1801 if (count == null) {
1802 Session session = null;
1803
1804 try {
1805 session = openSession();
1806
1807 Query q = session.createQuery(_SQL_COUNT_MBTHREADFLAG);
1808
1809 count = (Long)q.uniqueResult();
1810 }
1811 catch (Exception e) {
1812 throw processException(e);
1813 }
1814 finally {
1815 if (count == null) {
1816 count = Long.valueOf(0);
1817 }
1818
1819 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1820 FINDER_ARGS_EMPTY, count);
1821
1822 closeSession(session);
1823 }
1824 }
1825
1826 return count.intValue();
1827 }
1828
1829
1832 public void afterPropertiesSet() {
1833 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1834 com.liferay.portal.util.PropsUtil.get(
1835 "value.object.listener.com.liferay.portlet.messageboards.model.MBThreadFlag")));
1836
1837 if (listenerClassNames.length > 0) {
1838 try {
1839 List<ModelListener<MBThreadFlag>> listenersList = new ArrayList<ModelListener<MBThreadFlag>>();
1840
1841 for (String listenerClassName : listenerClassNames) {
1842 Class<?> clazz = getClass();
1843
1844 listenersList.add((ModelListener<MBThreadFlag>)InstanceFactory.newInstance(
1845 clazz.getClassLoader(), listenerClassName));
1846 }
1847
1848 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1849 }
1850 catch (Exception e) {
1851 _log.error(e);
1852 }
1853 }
1854 }
1855
1856 public void destroy() {
1857 EntityCacheUtil.removeCache(MBThreadFlagImpl.class.getName());
1858 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1859 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1860 }
1861
1862 @BeanReference(type = MBBanPersistence.class)
1863 protected MBBanPersistence mbBanPersistence;
1864 @BeanReference(type = MBCategoryPersistence.class)
1865 protected MBCategoryPersistence mbCategoryPersistence;
1866 @BeanReference(type = MBDiscussionPersistence.class)
1867 protected MBDiscussionPersistence mbDiscussionPersistence;
1868 @BeanReference(type = MBMailingListPersistence.class)
1869 protected MBMailingListPersistence mbMailingListPersistence;
1870 @BeanReference(type = MBMessagePersistence.class)
1871 protected MBMessagePersistence mbMessagePersistence;
1872 @BeanReference(type = MBStatsUserPersistence.class)
1873 protected MBStatsUserPersistence mbStatsUserPersistence;
1874 @BeanReference(type = MBThreadPersistence.class)
1875 protected MBThreadPersistence mbThreadPersistence;
1876 @BeanReference(type = MBThreadFlagPersistence.class)
1877 protected MBThreadFlagPersistence mbThreadFlagPersistence;
1878 @BeanReference(type = ResourcePersistence.class)
1879 protected ResourcePersistence resourcePersistence;
1880 @BeanReference(type = UserPersistence.class)
1881 protected UserPersistence userPersistence;
1882 private static final String _SQL_SELECT_MBTHREADFLAG = "SELECT mbThreadFlag FROM MBThreadFlag mbThreadFlag";
1883 private static final String _SQL_SELECT_MBTHREADFLAG_WHERE = "SELECT mbThreadFlag FROM MBThreadFlag mbThreadFlag WHERE ";
1884 private static final String _SQL_COUNT_MBTHREADFLAG = "SELECT COUNT(mbThreadFlag) FROM MBThreadFlag mbThreadFlag";
1885 private static final String _SQL_COUNT_MBTHREADFLAG_WHERE = "SELECT COUNT(mbThreadFlag) FROM MBThreadFlag mbThreadFlag WHERE ";
1886 private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbThreadFlag.userId = ?";
1887 private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbThreadFlag.threadId = ?";
1888 private static final String _FINDER_COLUMN_U_T_USERID_2 = "mbThreadFlag.userId = ? AND ";
1889 private static final String _FINDER_COLUMN_U_T_THREADID_2 = "mbThreadFlag.threadId = ?";
1890 private static final String _ORDER_BY_ENTITY_ALIAS = "mbThreadFlag.";
1891 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBThreadFlag exists with the primary key ";
1892 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBThreadFlag exists with the key {";
1893 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1894 private static Log _log = LogFactoryUtil.getLog(MBThreadFlagPersistenceImpl.class);
1895 private static MBThreadFlag _nullMBThreadFlag = new MBThreadFlagImpl() {
1896 @Override
1897 public Object clone() {
1898 return this;
1899 }
1900
1901 @Override
1902 public CacheModel<MBThreadFlag> toCacheModel() {
1903 return _nullMBThreadFlagCacheModel;
1904 }
1905 };
1906
1907 private static CacheModel<MBThreadFlag> _nullMBThreadFlagCacheModel = new CacheModel<MBThreadFlag>() {
1908 public MBThreadFlag toEntityModel() {
1909 return _nullMBThreadFlag;
1910 }
1911 };
1912 }