001
014
015 package com.liferay.portlet.announcements.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.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.ModelListener;
037 import com.liferay.portal.service.persistence.BatchSessionUtil;
038 import com.liferay.portal.service.persistence.ResourcePersistence;
039 import com.liferay.portal.service.persistence.UserPersistence;
040 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041
042 import com.liferay.portlet.announcements.NoSuchFlagException;
043 import com.liferay.portlet.announcements.model.AnnouncementsFlag;
044 import com.liferay.portlet.announcements.model.impl.AnnouncementsFlagImpl;
045 import com.liferay.portlet.announcements.model.impl.AnnouncementsFlagModelImpl;
046
047 import java.io.Serializable;
048
049 import java.util.ArrayList;
050 import java.util.Collections;
051 import java.util.List;
052
053
069 public class AnnouncementsFlagPersistenceImpl extends BasePersistenceImpl<AnnouncementsFlag>
070 implements AnnouncementsFlagPersistence {
071 public static final String FINDER_CLASS_NAME_ENTITY = AnnouncementsFlagImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
073 ".List";
074 public static final FinderPath FINDER_PATH_FIND_BY_ENTRYID = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
075 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
076 FINDER_CLASS_NAME_LIST, "findByEntryId",
077 new String[] {
078 Long.class.getName(),
079
080 "java.lang.Integer", "java.lang.Integer",
081 "com.liferay.portal.kernel.util.OrderByComparator"
082 });
083 public static final FinderPath FINDER_PATH_COUNT_BY_ENTRYID = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
084 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
085 FINDER_CLASS_NAME_LIST, "countByEntryId",
086 new String[] { Long.class.getName() });
087 public static final FinderPath FINDER_PATH_FETCH_BY_U_E_V = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
088 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
089 FINDER_CLASS_NAME_ENTITY, "fetchByU_E_V",
090 new String[] {
091 Long.class.getName(), Long.class.getName(),
092 Integer.class.getName()
093 });
094 public static final FinderPath FINDER_PATH_COUNT_BY_U_E_V = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
095 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
096 FINDER_CLASS_NAME_LIST, "countByU_E_V",
097 new String[] {
098 Long.class.getName(), Long.class.getName(),
099 Integer.class.getName()
100 });
101 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
102 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
103 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
104 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
105 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
106 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
107
108
113 public void cacheResult(AnnouncementsFlag announcementsFlag) {
114 EntityCacheUtil.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
115 AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey(),
116 announcementsFlag);
117
118 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
119 new Object[] {
120 new Long(announcementsFlag.getUserId()),
121 new Long(announcementsFlag.getEntryId()),
122 new Integer(announcementsFlag.getValue())
123 }, announcementsFlag);
124 }
125
126
131 public void cacheResult(List<AnnouncementsFlag> announcementsFlags) {
132 for (AnnouncementsFlag announcementsFlag : announcementsFlags) {
133 if (EntityCacheUtil.getResult(
134 AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
135 AnnouncementsFlagImpl.class,
136 announcementsFlag.getPrimaryKey(), this) == null) {
137 cacheResult(announcementsFlag);
138 }
139 }
140 }
141
142
149 public void clearCache() {
150 CacheRegistryUtil.clear(AnnouncementsFlagImpl.class.getName());
151 EntityCacheUtil.clearCache(AnnouncementsFlagImpl.class.getName());
152 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
153 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
154 }
155
156
163 public void clearCache(AnnouncementsFlag announcementsFlag) {
164 EntityCacheUtil.removeResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
165 AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey());
166
167 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V,
168 new Object[] {
169 new Long(announcementsFlag.getUserId()),
170 new Long(announcementsFlag.getEntryId()),
171 new Integer(announcementsFlag.getValue())
172 });
173 }
174
175
181 public AnnouncementsFlag create(long flagId) {
182 AnnouncementsFlag announcementsFlag = new AnnouncementsFlagImpl();
183
184 announcementsFlag.setNew(true);
185 announcementsFlag.setPrimaryKey(flagId);
186
187 return announcementsFlag;
188 }
189
190
198 public AnnouncementsFlag remove(Serializable primaryKey)
199 throws NoSuchModelException, SystemException {
200 return remove(((Long)primaryKey).longValue());
201 }
202
203
211 public AnnouncementsFlag remove(long flagId)
212 throws NoSuchFlagException, SystemException {
213 Session session = null;
214
215 try {
216 session = openSession();
217
218 AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)session.get(AnnouncementsFlagImpl.class,
219 new Long(flagId));
220
221 if (announcementsFlag == null) {
222 if (_log.isWarnEnabled()) {
223 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + flagId);
224 }
225
226 throw new NoSuchFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
227 flagId);
228 }
229
230 return remove(announcementsFlag);
231 }
232 catch (NoSuchFlagException nsee) {
233 throw nsee;
234 }
235 catch (Exception e) {
236 throw processException(e);
237 }
238 finally {
239 closeSession(session);
240 }
241 }
242
243 protected AnnouncementsFlag removeImpl(AnnouncementsFlag announcementsFlag)
244 throws SystemException {
245 announcementsFlag = toUnwrappedModel(announcementsFlag);
246
247 Session session = null;
248
249 try {
250 session = openSession();
251
252 BatchSessionUtil.delete(session, announcementsFlag);
253 }
254 catch (Exception e) {
255 throw processException(e);
256 }
257 finally {
258 closeSession(session);
259 }
260
261 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
262
263 AnnouncementsFlagModelImpl announcementsFlagModelImpl = (AnnouncementsFlagModelImpl)announcementsFlag;
264
265 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V,
266 new Object[] {
267 new Long(announcementsFlagModelImpl.getUserId()),
268 new Long(announcementsFlagModelImpl.getEntryId()),
269 new Integer(announcementsFlagModelImpl.getValue())
270 });
271
272 EntityCacheUtil.removeResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
273 AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey());
274
275 return announcementsFlag;
276 }
277
278 public AnnouncementsFlag updateImpl(
279 com.liferay.portlet.announcements.model.AnnouncementsFlag announcementsFlag,
280 boolean merge) throws SystemException {
281 announcementsFlag = toUnwrappedModel(announcementsFlag);
282
283 boolean isNew = announcementsFlag.isNew();
284
285 AnnouncementsFlagModelImpl announcementsFlagModelImpl = (AnnouncementsFlagModelImpl)announcementsFlag;
286
287 Session session = null;
288
289 try {
290 session = openSession();
291
292 BatchSessionUtil.update(session, announcementsFlag, merge);
293
294 announcementsFlag.setNew(false);
295 }
296 catch (Exception e) {
297 throw processException(e);
298 }
299 finally {
300 closeSession(session);
301 }
302
303 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
304
305 EntityCacheUtil.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
306 AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey(),
307 announcementsFlag);
308
309 if (!isNew &&
310 ((announcementsFlag.getUserId() != announcementsFlagModelImpl.getOriginalUserId()) ||
311 (announcementsFlag.getEntryId() != announcementsFlagModelImpl.getOriginalEntryId()) ||
312 (announcementsFlag.getValue() != announcementsFlagModelImpl.getOriginalValue()))) {
313 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V,
314 new Object[] {
315 new Long(announcementsFlagModelImpl.getOriginalUserId()),
316 new Long(announcementsFlagModelImpl.getOriginalEntryId()),
317 new Integer(announcementsFlagModelImpl.getOriginalValue())
318 });
319 }
320
321 if (isNew ||
322 ((announcementsFlag.getUserId() != announcementsFlagModelImpl.getOriginalUserId()) ||
323 (announcementsFlag.getEntryId() != announcementsFlagModelImpl.getOriginalEntryId()) ||
324 (announcementsFlag.getValue() != announcementsFlagModelImpl.getOriginalValue()))) {
325 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
326 new Object[] {
327 new Long(announcementsFlag.getUserId()),
328 new Long(announcementsFlag.getEntryId()),
329 new Integer(announcementsFlag.getValue())
330 }, announcementsFlag);
331 }
332
333 return announcementsFlag;
334 }
335
336 protected AnnouncementsFlag toUnwrappedModel(
337 AnnouncementsFlag announcementsFlag) {
338 if (announcementsFlag instanceof AnnouncementsFlagImpl) {
339 return announcementsFlag;
340 }
341
342 AnnouncementsFlagImpl announcementsFlagImpl = new AnnouncementsFlagImpl();
343
344 announcementsFlagImpl.setNew(announcementsFlag.isNew());
345 announcementsFlagImpl.setPrimaryKey(announcementsFlag.getPrimaryKey());
346
347 announcementsFlagImpl.setFlagId(announcementsFlag.getFlagId());
348 announcementsFlagImpl.setUserId(announcementsFlag.getUserId());
349 announcementsFlagImpl.setCreateDate(announcementsFlag.getCreateDate());
350 announcementsFlagImpl.setEntryId(announcementsFlag.getEntryId());
351 announcementsFlagImpl.setValue(announcementsFlag.getValue());
352
353 return announcementsFlagImpl;
354 }
355
356
364 public AnnouncementsFlag findByPrimaryKey(Serializable primaryKey)
365 throws NoSuchModelException, SystemException {
366 return findByPrimaryKey(((Long)primaryKey).longValue());
367 }
368
369
377 public AnnouncementsFlag findByPrimaryKey(long flagId)
378 throws NoSuchFlagException, SystemException {
379 AnnouncementsFlag announcementsFlag = fetchByPrimaryKey(flagId);
380
381 if (announcementsFlag == null) {
382 if (_log.isWarnEnabled()) {
383 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + flagId);
384 }
385
386 throw new NoSuchFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
387 flagId);
388 }
389
390 return announcementsFlag;
391 }
392
393
400 public AnnouncementsFlag fetchByPrimaryKey(Serializable primaryKey)
401 throws SystemException {
402 return fetchByPrimaryKey(((Long)primaryKey).longValue());
403 }
404
405
412 public AnnouncementsFlag fetchByPrimaryKey(long flagId)
413 throws SystemException {
414 AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)EntityCacheUtil.getResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
415 AnnouncementsFlagImpl.class, flagId, this);
416
417 if (announcementsFlag == null) {
418 Session session = null;
419
420 try {
421 session = openSession();
422
423 announcementsFlag = (AnnouncementsFlag)session.get(AnnouncementsFlagImpl.class,
424 new Long(flagId));
425 }
426 catch (Exception e) {
427 throw processException(e);
428 }
429 finally {
430 if (announcementsFlag != null) {
431 cacheResult(announcementsFlag);
432 }
433
434 closeSession(session);
435 }
436 }
437
438 return announcementsFlag;
439 }
440
441
448 public List<AnnouncementsFlag> findByEntryId(long entryId)
449 throws SystemException {
450 return findByEntryId(entryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
451 }
452
453
466 public List<AnnouncementsFlag> findByEntryId(long entryId, int start,
467 int end) throws SystemException {
468 return findByEntryId(entryId, start, end, null);
469 }
470
471
485 public List<AnnouncementsFlag> findByEntryId(long entryId, int start,
486 int end, OrderByComparator orderByComparator) throws SystemException {
487 Object[] finderArgs = new Object[] {
488 entryId,
489
490 String.valueOf(start), String.valueOf(end),
491 String.valueOf(orderByComparator)
492 };
493
494 List<AnnouncementsFlag> list = (List<AnnouncementsFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ENTRYID,
495 finderArgs, this);
496
497 if (list == null) {
498 StringBundler query = null;
499
500 if (orderByComparator != null) {
501 query = new StringBundler(3 +
502 (orderByComparator.getOrderByFields().length * 3));
503 }
504 else {
505 query = new StringBundler(3);
506 }
507
508 query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
509
510 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
511
512 if (orderByComparator != null) {
513 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
514 orderByComparator);
515 }
516
517 else {
518 query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
519 }
520
521 String sql = query.toString();
522
523 Session session = null;
524
525 try {
526 session = openSession();
527
528 Query q = session.createQuery(sql);
529
530 QueryPos qPos = QueryPos.getInstance(q);
531
532 qPos.add(entryId);
533
534 list = (List<AnnouncementsFlag>)QueryUtil.list(q, getDialect(),
535 start, end);
536 }
537 catch (Exception e) {
538 throw processException(e);
539 }
540 finally {
541 if (list == null) {
542 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_ENTRYID,
543 finderArgs);
544 }
545 else {
546 cacheResult(list);
547
548 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ENTRYID,
549 finderArgs, list);
550 }
551
552 closeSession(session);
553 }
554 }
555
556 return list;
557 }
558
559
572 public AnnouncementsFlag findByEntryId_First(long entryId,
573 OrderByComparator orderByComparator)
574 throws NoSuchFlagException, SystemException {
575 List<AnnouncementsFlag> list = findByEntryId(entryId, 0, 1,
576 orderByComparator);
577
578 if (list.isEmpty()) {
579 StringBundler msg = new StringBundler(4);
580
581 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
582
583 msg.append("entryId=");
584 msg.append(entryId);
585
586 msg.append(StringPool.CLOSE_CURLY_BRACE);
587
588 throw new NoSuchFlagException(msg.toString());
589 }
590 else {
591 return list.get(0);
592 }
593 }
594
595
608 public AnnouncementsFlag findByEntryId_Last(long entryId,
609 OrderByComparator orderByComparator)
610 throws NoSuchFlagException, SystemException {
611 int count = countByEntryId(entryId);
612
613 List<AnnouncementsFlag> list = findByEntryId(entryId, count - 1, count,
614 orderByComparator);
615
616 if (list.isEmpty()) {
617 StringBundler msg = new StringBundler(4);
618
619 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
620
621 msg.append("entryId=");
622 msg.append(entryId);
623
624 msg.append(StringPool.CLOSE_CURLY_BRACE);
625
626 throw new NoSuchFlagException(msg.toString());
627 }
628 else {
629 return list.get(0);
630 }
631 }
632
633
647 public AnnouncementsFlag[] findByEntryId_PrevAndNext(long flagId,
648 long entryId, OrderByComparator orderByComparator)
649 throws NoSuchFlagException, SystemException {
650 AnnouncementsFlag announcementsFlag = findByPrimaryKey(flagId);
651
652 Session session = null;
653
654 try {
655 session = openSession();
656
657 AnnouncementsFlag[] array = new AnnouncementsFlagImpl[3];
658
659 array[0] = getByEntryId_PrevAndNext(session, announcementsFlag,
660 entryId, orderByComparator, true);
661
662 array[1] = announcementsFlag;
663
664 array[2] = getByEntryId_PrevAndNext(session, announcementsFlag,
665 entryId, orderByComparator, false);
666
667 return array;
668 }
669 catch (Exception e) {
670 throw processException(e);
671 }
672 finally {
673 closeSession(session);
674 }
675 }
676
677 protected AnnouncementsFlag getByEntryId_PrevAndNext(Session session,
678 AnnouncementsFlag announcementsFlag, long entryId,
679 OrderByComparator orderByComparator, boolean previous) {
680 StringBundler query = null;
681
682 if (orderByComparator != null) {
683 query = new StringBundler(6 +
684 (orderByComparator.getOrderByFields().length * 6));
685 }
686 else {
687 query = new StringBundler(3);
688 }
689
690 query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
691
692 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
693
694 if (orderByComparator != null) {
695 String[] orderByFields = orderByComparator.getOrderByFields();
696
697 if (orderByFields.length > 0) {
698 query.append(WHERE_AND);
699 }
700
701 for (int i = 0; i < orderByFields.length; i++) {
702 query.append(_ORDER_BY_ENTITY_ALIAS);
703 query.append(orderByFields[i]);
704
705 if ((i + 1) < orderByFields.length) {
706 if (orderByComparator.isAscending() ^ previous) {
707 query.append(WHERE_GREATER_THAN_HAS_NEXT);
708 }
709 else {
710 query.append(WHERE_LESSER_THAN_HAS_NEXT);
711 }
712 }
713 else {
714 if (orderByComparator.isAscending() ^ previous) {
715 query.append(WHERE_GREATER_THAN);
716 }
717 else {
718 query.append(WHERE_LESSER_THAN);
719 }
720 }
721 }
722
723 query.append(ORDER_BY_CLAUSE);
724
725 for (int i = 0; i < orderByFields.length; i++) {
726 query.append(_ORDER_BY_ENTITY_ALIAS);
727 query.append(orderByFields[i]);
728
729 if ((i + 1) < orderByFields.length) {
730 if (orderByComparator.isAscending() ^ previous) {
731 query.append(ORDER_BY_ASC_HAS_NEXT);
732 }
733 else {
734 query.append(ORDER_BY_DESC_HAS_NEXT);
735 }
736 }
737 else {
738 if (orderByComparator.isAscending() ^ previous) {
739 query.append(ORDER_BY_ASC);
740 }
741 else {
742 query.append(ORDER_BY_DESC);
743 }
744 }
745 }
746 }
747
748 else {
749 query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
750 }
751
752 String sql = query.toString();
753
754 Query q = session.createQuery(sql);
755
756 q.setFirstResult(0);
757 q.setMaxResults(2);
758
759 QueryPos qPos = QueryPos.getInstance(q);
760
761 qPos.add(entryId);
762
763 if (orderByComparator != null) {
764 Object[] values = orderByComparator.getOrderByValues(announcementsFlag);
765
766 for (Object value : values) {
767 qPos.add(value);
768 }
769 }
770
771 List<AnnouncementsFlag> list = q.list();
772
773 if (list.size() == 2) {
774 return list.get(1);
775 }
776 else {
777 return null;
778 }
779 }
780
781
791 public AnnouncementsFlag findByU_E_V(long userId, long entryId, int value)
792 throws NoSuchFlagException, SystemException {
793 AnnouncementsFlag announcementsFlag = fetchByU_E_V(userId, entryId,
794 value);
795
796 if (announcementsFlag == null) {
797 StringBundler msg = new StringBundler(8);
798
799 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
800
801 msg.append("userId=");
802 msg.append(userId);
803
804 msg.append(", entryId=");
805 msg.append(entryId);
806
807 msg.append(", value=");
808 msg.append(value);
809
810 msg.append(StringPool.CLOSE_CURLY_BRACE);
811
812 if (_log.isWarnEnabled()) {
813 _log.warn(msg.toString());
814 }
815
816 throw new NoSuchFlagException(msg.toString());
817 }
818
819 return announcementsFlag;
820 }
821
822
831 public AnnouncementsFlag fetchByU_E_V(long userId, long entryId, int value)
832 throws SystemException {
833 return fetchByU_E_V(userId, entryId, value, true);
834 }
835
836
845 public AnnouncementsFlag fetchByU_E_V(long userId, long entryId, int value,
846 boolean retrieveFromCache) throws SystemException {
847 Object[] finderArgs = new Object[] { userId, entryId, value };
848
849 Object result = null;
850
851 if (retrieveFromCache) {
852 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_E_V,
853 finderArgs, this);
854 }
855
856 if (result == null) {
857 StringBundler query = new StringBundler(5);
858
859 query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
860
861 query.append(_FINDER_COLUMN_U_E_V_USERID_2);
862
863 query.append(_FINDER_COLUMN_U_E_V_ENTRYID_2);
864
865 query.append(_FINDER_COLUMN_U_E_V_VALUE_2);
866
867 query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
868
869 String sql = query.toString();
870
871 Session session = null;
872
873 try {
874 session = openSession();
875
876 Query q = session.createQuery(sql);
877
878 QueryPos qPos = QueryPos.getInstance(q);
879
880 qPos.add(userId);
881
882 qPos.add(entryId);
883
884 qPos.add(value);
885
886 List<AnnouncementsFlag> list = q.list();
887
888 result = list;
889
890 AnnouncementsFlag announcementsFlag = null;
891
892 if (list.isEmpty()) {
893 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
894 finderArgs, list);
895 }
896 else {
897 announcementsFlag = list.get(0);
898
899 cacheResult(announcementsFlag);
900
901 if ((announcementsFlag.getUserId() != userId) ||
902 (announcementsFlag.getEntryId() != entryId) ||
903 (announcementsFlag.getValue() != value)) {
904 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
905 finderArgs, announcementsFlag);
906 }
907 }
908
909 return announcementsFlag;
910 }
911 catch (Exception e) {
912 throw processException(e);
913 }
914 finally {
915 if (result == null) {
916 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V,
917 finderArgs);
918 }
919
920 closeSession(session);
921 }
922 }
923 else {
924 if (result instanceof List<?>) {
925 return null;
926 }
927 else {
928 return (AnnouncementsFlag)result;
929 }
930 }
931 }
932
933
939 public List<AnnouncementsFlag> findAll() throws SystemException {
940 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
941 }
942
943
955 public List<AnnouncementsFlag> findAll(int start, int end)
956 throws SystemException {
957 return findAll(start, end, null);
958 }
959
960
973 public List<AnnouncementsFlag> findAll(int start, int end,
974 OrderByComparator orderByComparator) throws SystemException {
975 Object[] finderArgs = new Object[] {
976 String.valueOf(start), String.valueOf(end),
977 String.valueOf(orderByComparator)
978 };
979
980 List<AnnouncementsFlag> list = (List<AnnouncementsFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
981 finderArgs, this);
982
983 if (list == null) {
984 StringBundler query = null;
985 String sql = null;
986
987 if (orderByComparator != null) {
988 query = new StringBundler(2 +
989 (orderByComparator.getOrderByFields().length * 3));
990
991 query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG);
992
993 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
994 orderByComparator);
995
996 sql = query.toString();
997 }
998 else {
999 sql = _SQL_SELECT_ANNOUNCEMENTSFLAG.concat(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
1000 }
1001
1002 Session session = null;
1003
1004 try {
1005 session = openSession();
1006
1007 Query q = session.createQuery(sql);
1008
1009 if (orderByComparator == null) {
1010 list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1011 getDialect(), start, end, false);
1012
1013 Collections.sort(list);
1014 }
1015 else {
1016 list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1017 getDialect(), start, end);
1018 }
1019 }
1020 catch (Exception e) {
1021 throw processException(e);
1022 }
1023 finally {
1024 if (list == null) {
1025 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1026 finderArgs);
1027 }
1028 else {
1029 cacheResult(list);
1030
1031 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1032 list);
1033 }
1034
1035 closeSession(session);
1036 }
1037 }
1038
1039 return list;
1040 }
1041
1042
1048 public void removeByEntryId(long entryId) throws SystemException {
1049 for (AnnouncementsFlag announcementsFlag : findByEntryId(entryId)) {
1050 remove(announcementsFlag);
1051 }
1052 }
1053
1054
1062 public void removeByU_E_V(long userId, long entryId, int value)
1063 throws NoSuchFlagException, SystemException {
1064 AnnouncementsFlag announcementsFlag = findByU_E_V(userId, entryId, value);
1065
1066 remove(announcementsFlag);
1067 }
1068
1069
1074 public void removeAll() throws SystemException {
1075 for (AnnouncementsFlag announcementsFlag : findAll()) {
1076 remove(announcementsFlag);
1077 }
1078 }
1079
1080
1087 public int countByEntryId(long entryId) throws SystemException {
1088 Object[] finderArgs = new Object[] { entryId };
1089
1090 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ENTRYID,
1091 finderArgs, this);
1092
1093 if (count == null) {
1094 StringBundler query = new StringBundler(2);
1095
1096 query.append(_SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE);
1097
1098 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
1099
1100 String sql = query.toString();
1101
1102 Session session = null;
1103
1104 try {
1105 session = openSession();
1106
1107 Query q = session.createQuery(sql);
1108
1109 QueryPos qPos = QueryPos.getInstance(q);
1110
1111 qPos.add(entryId);
1112
1113 count = (Long)q.uniqueResult();
1114 }
1115 catch (Exception e) {
1116 throw processException(e);
1117 }
1118 finally {
1119 if (count == null) {
1120 count = Long.valueOf(0);
1121 }
1122
1123 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ENTRYID,
1124 finderArgs, count);
1125
1126 closeSession(session);
1127 }
1128 }
1129
1130 return count.intValue();
1131 }
1132
1133
1142 public int countByU_E_V(long userId, long entryId, int value)
1143 throws SystemException {
1144 Object[] finderArgs = new Object[] { userId, entryId, value };
1145
1146 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_E_V,
1147 finderArgs, this);
1148
1149 if (count == null) {
1150 StringBundler query = new StringBundler(4);
1151
1152 query.append(_SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE);
1153
1154 query.append(_FINDER_COLUMN_U_E_V_USERID_2);
1155
1156 query.append(_FINDER_COLUMN_U_E_V_ENTRYID_2);
1157
1158 query.append(_FINDER_COLUMN_U_E_V_VALUE_2);
1159
1160 String sql = query.toString();
1161
1162 Session session = null;
1163
1164 try {
1165 session = openSession();
1166
1167 Query q = session.createQuery(sql);
1168
1169 QueryPos qPos = QueryPos.getInstance(q);
1170
1171 qPos.add(userId);
1172
1173 qPos.add(entryId);
1174
1175 qPos.add(value);
1176
1177 count = (Long)q.uniqueResult();
1178 }
1179 catch (Exception e) {
1180 throw processException(e);
1181 }
1182 finally {
1183 if (count == null) {
1184 count = Long.valueOf(0);
1185 }
1186
1187 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_E_V,
1188 finderArgs, count);
1189
1190 closeSession(session);
1191 }
1192 }
1193
1194 return count.intValue();
1195 }
1196
1197
1203 public int countAll() throws SystemException {
1204 Object[] finderArgs = new Object[0];
1205
1206 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1207 finderArgs, this);
1208
1209 if (count == null) {
1210 Session session = null;
1211
1212 try {
1213 session = openSession();
1214
1215 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSFLAG);
1216
1217 count = (Long)q.uniqueResult();
1218 }
1219 catch (Exception e) {
1220 throw processException(e);
1221 }
1222 finally {
1223 if (count == null) {
1224 count = Long.valueOf(0);
1225 }
1226
1227 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1228 count);
1229
1230 closeSession(session);
1231 }
1232 }
1233
1234 return count.intValue();
1235 }
1236
1237
1240 public void afterPropertiesSet() {
1241 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1242 com.liferay.portal.util.PropsUtil.get(
1243 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsFlag")));
1244
1245 if (listenerClassNames.length > 0) {
1246 try {
1247 List<ModelListener<AnnouncementsFlag>> listenersList = new ArrayList<ModelListener<AnnouncementsFlag>>();
1248
1249 for (String listenerClassName : listenerClassNames) {
1250 listenersList.add((ModelListener<AnnouncementsFlag>)InstanceFactory.newInstance(
1251 listenerClassName));
1252 }
1253
1254 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1255 }
1256 catch (Exception e) {
1257 _log.error(e);
1258 }
1259 }
1260 }
1261
1262 public void destroy() {
1263 EntityCacheUtil.removeCache(AnnouncementsFlagImpl.class.getName());
1264 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1265 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1266 }
1267
1268 @BeanReference(type = AnnouncementsDeliveryPersistence.class)
1269 protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1270 @BeanReference(type = AnnouncementsEntryPersistence.class)
1271 protected AnnouncementsEntryPersistence announcementsEntryPersistence;
1272 @BeanReference(type = AnnouncementsFlagPersistence.class)
1273 protected AnnouncementsFlagPersistence announcementsFlagPersistence;
1274 @BeanReference(type = ResourcePersistence.class)
1275 protected ResourcePersistence resourcePersistence;
1276 @BeanReference(type = UserPersistence.class)
1277 protected UserPersistence userPersistence;
1278 private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag";
1279 private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag WHERE ";
1280 private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag";
1281 private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag WHERE ";
1282 private static final String _FINDER_COLUMN_ENTRYID_ENTRYID_2 = "announcementsFlag.entryId = ?";
1283 private static final String _FINDER_COLUMN_U_E_V_USERID_2 = "announcementsFlag.userId = ? AND ";
1284 private static final String _FINDER_COLUMN_U_E_V_ENTRYID_2 = "announcementsFlag.entryId = ? AND ";
1285 private static final String _FINDER_COLUMN_U_E_V_VALUE_2 = "announcementsFlag.value = ?";
1286 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsFlag.";
1287 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsFlag exists with the primary key ";
1288 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsFlag exists with the key {";
1289 private static Log _log = LogFactoryUtil.getLog(AnnouncementsFlagPersistenceImpl.class);
1290 }