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.getOriginalUserId()),
268 new Long(announcementsFlagModelImpl.getOriginalEntryId()),
269 new Integer(announcementsFlagModelImpl.getOriginalValue())
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 Session session = null;
499
500 try {
501 session = openSession();
502
503 StringBundler query = null;
504
505 if (orderByComparator != null) {
506 query = new StringBundler(3 +
507 (orderByComparator.getOrderByFields().length * 3));
508 }
509 else {
510 query = new StringBundler(3);
511 }
512
513 query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
514
515 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
516
517 if (orderByComparator != null) {
518 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
519 orderByComparator);
520 }
521
522 else {
523 query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
524 }
525
526 String sql = query.toString();
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 list = new ArrayList<AnnouncementsFlag>();
543 }
544
545 cacheResult(list);
546
547 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ENTRYID,
548 finderArgs, list);
549
550 closeSession(session);
551 }
552 }
553
554 return list;
555 }
556
557
570 public AnnouncementsFlag findByEntryId_First(long entryId,
571 OrderByComparator orderByComparator)
572 throws NoSuchFlagException, SystemException {
573 List<AnnouncementsFlag> list = findByEntryId(entryId, 0, 1,
574 orderByComparator);
575
576 if (list.isEmpty()) {
577 StringBundler msg = new StringBundler(4);
578
579 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
580
581 msg.append("entryId=");
582 msg.append(entryId);
583
584 msg.append(StringPool.CLOSE_CURLY_BRACE);
585
586 throw new NoSuchFlagException(msg.toString());
587 }
588 else {
589 return list.get(0);
590 }
591 }
592
593
606 public AnnouncementsFlag findByEntryId_Last(long entryId,
607 OrderByComparator orderByComparator)
608 throws NoSuchFlagException, SystemException {
609 int count = countByEntryId(entryId);
610
611 List<AnnouncementsFlag> list = findByEntryId(entryId, count - 1, count,
612 orderByComparator);
613
614 if (list.isEmpty()) {
615 StringBundler msg = new StringBundler(4);
616
617 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
618
619 msg.append("entryId=");
620 msg.append(entryId);
621
622 msg.append(StringPool.CLOSE_CURLY_BRACE);
623
624 throw new NoSuchFlagException(msg.toString());
625 }
626 else {
627 return list.get(0);
628 }
629 }
630
631
645 public AnnouncementsFlag[] findByEntryId_PrevAndNext(long flagId,
646 long entryId, OrderByComparator orderByComparator)
647 throws NoSuchFlagException, SystemException {
648 AnnouncementsFlag announcementsFlag = findByPrimaryKey(flagId);
649
650 Session session = null;
651
652 try {
653 session = openSession();
654
655 AnnouncementsFlag[] array = new AnnouncementsFlagImpl[3];
656
657 array[0] = getByEntryId_PrevAndNext(session, announcementsFlag,
658 entryId, orderByComparator, true);
659
660 array[1] = announcementsFlag;
661
662 array[2] = getByEntryId_PrevAndNext(session, announcementsFlag,
663 entryId, orderByComparator, false);
664
665 return array;
666 }
667 catch (Exception e) {
668 throw processException(e);
669 }
670 finally {
671 closeSession(session);
672 }
673 }
674
675 protected AnnouncementsFlag getByEntryId_PrevAndNext(Session session,
676 AnnouncementsFlag announcementsFlag, long entryId,
677 OrderByComparator orderByComparator, boolean previous) {
678 StringBundler query = null;
679
680 if (orderByComparator != null) {
681 query = new StringBundler(6 +
682 (orderByComparator.getOrderByFields().length * 6));
683 }
684 else {
685 query = new StringBundler(3);
686 }
687
688 query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
689
690 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
691
692 if (orderByComparator != null) {
693 String[] orderByFields = orderByComparator.getOrderByFields();
694
695 if (orderByFields.length > 0) {
696 query.append(WHERE_AND);
697 }
698
699 for (int i = 0; i < orderByFields.length; i++) {
700 query.append(_ORDER_BY_ENTITY_ALIAS);
701 query.append(orderByFields[i]);
702
703 if ((i + 1) < orderByFields.length) {
704 if (orderByComparator.isAscending() ^ previous) {
705 query.append(WHERE_GREATER_THAN_HAS_NEXT);
706 }
707 else {
708 query.append(WHERE_LESSER_THAN_HAS_NEXT);
709 }
710 }
711 else {
712 if (orderByComparator.isAscending() ^ previous) {
713 query.append(WHERE_GREATER_THAN);
714 }
715 else {
716 query.append(WHERE_LESSER_THAN);
717 }
718 }
719 }
720
721 query.append(ORDER_BY_CLAUSE);
722
723 for (int i = 0; i < orderByFields.length; i++) {
724 query.append(_ORDER_BY_ENTITY_ALIAS);
725 query.append(orderByFields[i]);
726
727 if ((i + 1) < orderByFields.length) {
728 if (orderByComparator.isAscending() ^ previous) {
729 query.append(ORDER_BY_ASC_HAS_NEXT);
730 }
731 else {
732 query.append(ORDER_BY_DESC_HAS_NEXT);
733 }
734 }
735 else {
736 if (orderByComparator.isAscending() ^ previous) {
737 query.append(ORDER_BY_ASC);
738 }
739 else {
740 query.append(ORDER_BY_DESC);
741 }
742 }
743 }
744 }
745
746 else {
747 query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
748 }
749
750 String sql = query.toString();
751
752 Query q = session.createQuery(sql);
753
754 q.setFirstResult(0);
755 q.setMaxResults(2);
756
757 QueryPos qPos = QueryPos.getInstance(q);
758
759 qPos.add(entryId);
760
761 if (orderByComparator != null) {
762 Object[] values = orderByComparator.getOrderByValues(announcementsFlag);
763
764 for (Object value : values) {
765 qPos.add(value);
766 }
767 }
768
769 List<AnnouncementsFlag> list = q.list();
770
771 if (list.size() == 2) {
772 return list.get(1);
773 }
774 else {
775 return null;
776 }
777 }
778
779
789 public AnnouncementsFlag findByU_E_V(long userId, long entryId, int value)
790 throws NoSuchFlagException, SystemException {
791 AnnouncementsFlag announcementsFlag = fetchByU_E_V(userId, entryId,
792 value);
793
794 if (announcementsFlag == null) {
795 StringBundler msg = new StringBundler(8);
796
797 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
798
799 msg.append("userId=");
800 msg.append(userId);
801
802 msg.append(", entryId=");
803 msg.append(entryId);
804
805 msg.append(", value=");
806 msg.append(value);
807
808 msg.append(StringPool.CLOSE_CURLY_BRACE);
809
810 if (_log.isWarnEnabled()) {
811 _log.warn(msg.toString());
812 }
813
814 throw new NoSuchFlagException(msg.toString());
815 }
816
817 return announcementsFlag;
818 }
819
820
829 public AnnouncementsFlag fetchByU_E_V(long userId, long entryId, int value)
830 throws SystemException {
831 return fetchByU_E_V(userId, entryId, value, true);
832 }
833
834
843 public AnnouncementsFlag fetchByU_E_V(long userId, long entryId, int value,
844 boolean retrieveFromCache) throws SystemException {
845 Object[] finderArgs = new Object[] { userId, entryId, value };
846
847 Object result = null;
848
849 if (retrieveFromCache) {
850 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_E_V,
851 finderArgs, this);
852 }
853
854 if (result == null) {
855 Session session = null;
856
857 try {
858 session = openSession();
859
860 StringBundler query = new StringBundler(5);
861
862 query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
863
864 query.append(_FINDER_COLUMN_U_E_V_USERID_2);
865
866 query.append(_FINDER_COLUMN_U_E_V_ENTRYID_2);
867
868 query.append(_FINDER_COLUMN_U_E_V_VALUE_2);
869
870 query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
871
872 String sql = query.toString();
873
874 Query q = session.createQuery(sql);
875
876 QueryPos qPos = QueryPos.getInstance(q);
877
878 qPos.add(userId);
879
880 qPos.add(entryId);
881
882 qPos.add(value);
883
884 List<AnnouncementsFlag> list = q.list();
885
886 result = list;
887
888 AnnouncementsFlag announcementsFlag = null;
889
890 if (list.isEmpty()) {
891 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
892 finderArgs, list);
893 }
894 else {
895 announcementsFlag = list.get(0);
896
897 cacheResult(announcementsFlag);
898
899 if ((announcementsFlag.getUserId() != userId) ||
900 (announcementsFlag.getEntryId() != entryId) ||
901 (announcementsFlag.getValue() != value)) {
902 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
903 finderArgs, announcementsFlag);
904 }
905 }
906
907 return announcementsFlag;
908 }
909 catch (Exception e) {
910 throw processException(e);
911 }
912 finally {
913 if (result == null) {
914 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
915 finderArgs, new ArrayList<AnnouncementsFlag>());
916 }
917
918 closeSession(session);
919 }
920 }
921 else {
922 if (result instanceof List<?>) {
923 return null;
924 }
925 else {
926 return (AnnouncementsFlag)result;
927 }
928 }
929 }
930
931
937 public List<AnnouncementsFlag> findAll() throws SystemException {
938 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
939 }
940
941
953 public List<AnnouncementsFlag> findAll(int start, int end)
954 throws SystemException {
955 return findAll(start, end, null);
956 }
957
958
971 public List<AnnouncementsFlag> findAll(int start, int end,
972 OrderByComparator orderByComparator) throws SystemException {
973 Object[] finderArgs = new Object[] {
974 String.valueOf(start), String.valueOf(end),
975 String.valueOf(orderByComparator)
976 };
977
978 List<AnnouncementsFlag> list = (List<AnnouncementsFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
979 finderArgs, this);
980
981 if (list == null) {
982 Session session = null;
983
984 try {
985 session = openSession();
986
987 StringBundler query = null;
988 String sql = null;
989
990 if (orderByComparator != null) {
991 query = new StringBundler(2 +
992 (orderByComparator.getOrderByFields().length * 3));
993
994 query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG);
995
996 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
997 orderByComparator);
998
999 sql = query.toString();
1000 }
1001 else {
1002 sql = _SQL_SELECT_ANNOUNCEMENTSFLAG.concat(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
1003 }
1004
1005 Query q = session.createQuery(sql);
1006
1007 if (orderByComparator == null) {
1008 list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1009 getDialect(), start, end, false);
1010
1011 Collections.sort(list);
1012 }
1013 else {
1014 list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1015 getDialect(), start, end);
1016 }
1017 }
1018 catch (Exception e) {
1019 throw processException(e);
1020 }
1021 finally {
1022 if (list == null) {
1023 list = new ArrayList<AnnouncementsFlag>();
1024 }
1025
1026 cacheResult(list);
1027
1028 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1029
1030 closeSession(session);
1031 }
1032 }
1033
1034 return list;
1035 }
1036
1037
1043 public void removeByEntryId(long entryId) throws SystemException {
1044 for (AnnouncementsFlag announcementsFlag : findByEntryId(entryId)) {
1045 remove(announcementsFlag);
1046 }
1047 }
1048
1049
1057 public void removeByU_E_V(long userId, long entryId, int value)
1058 throws NoSuchFlagException, SystemException {
1059 AnnouncementsFlag announcementsFlag = findByU_E_V(userId, entryId, value);
1060
1061 remove(announcementsFlag);
1062 }
1063
1064
1069 public void removeAll() throws SystemException {
1070 for (AnnouncementsFlag announcementsFlag : findAll()) {
1071 remove(announcementsFlag);
1072 }
1073 }
1074
1075
1082 public int countByEntryId(long entryId) throws SystemException {
1083 Object[] finderArgs = new Object[] { entryId };
1084
1085 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ENTRYID,
1086 finderArgs, this);
1087
1088 if (count == null) {
1089 Session session = null;
1090
1091 try {
1092 session = openSession();
1093
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 Query q = session.createQuery(sql);
1103
1104 QueryPos qPos = QueryPos.getInstance(q);
1105
1106 qPos.add(entryId);
1107
1108 count = (Long)q.uniqueResult();
1109 }
1110 catch (Exception e) {
1111 throw processException(e);
1112 }
1113 finally {
1114 if (count == null) {
1115 count = Long.valueOf(0);
1116 }
1117
1118 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ENTRYID,
1119 finderArgs, count);
1120
1121 closeSession(session);
1122 }
1123 }
1124
1125 return count.intValue();
1126 }
1127
1128
1137 public int countByU_E_V(long userId, long entryId, int value)
1138 throws SystemException {
1139 Object[] finderArgs = new Object[] { userId, entryId, value };
1140
1141 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_E_V,
1142 finderArgs, this);
1143
1144 if (count == null) {
1145 Session session = null;
1146
1147 try {
1148 session = openSession();
1149
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 Query q = session.createQuery(sql);
1163
1164 QueryPos qPos = QueryPos.getInstance(q);
1165
1166 qPos.add(userId);
1167
1168 qPos.add(entryId);
1169
1170 qPos.add(value);
1171
1172 count = (Long)q.uniqueResult();
1173 }
1174 catch (Exception e) {
1175 throw processException(e);
1176 }
1177 finally {
1178 if (count == null) {
1179 count = Long.valueOf(0);
1180 }
1181
1182 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_E_V,
1183 finderArgs, count);
1184
1185 closeSession(session);
1186 }
1187 }
1188
1189 return count.intValue();
1190 }
1191
1192
1198 public int countAll() throws SystemException {
1199 Object[] finderArgs = new Object[0];
1200
1201 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1202 finderArgs, this);
1203
1204 if (count == null) {
1205 Session session = null;
1206
1207 try {
1208 session = openSession();
1209
1210 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSFLAG);
1211
1212 count = (Long)q.uniqueResult();
1213 }
1214 catch (Exception e) {
1215 throw processException(e);
1216 }
1217 finally {
1218 if (count == null) {
1219 count = Long.valueOf(0);
1220 }
1221
1222 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1223 count);
1224
1225 closeSession(session);
1226 }
1227 }
1228
1229 return count.intValue();
1230 }
1231
1232
1235 public void afterPropertiesSet() {
1236 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1237 com.liferay.portal.util.PropsUtil.get(
1238 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsFlag")));
1239
1240 if (listenerClassNames.length > 0) {
1241 try {
1242 List<ModelListener<AnnouncementsFlag>> listenersList = new ArrayList<ModelListener<AnnouncementsFlag>>();
1243
1244 for (String listenerClassName : listenerClassNames) {
1245 listenersList.add((ModelListener<AnnouncementsFlag>)InstanceFactory.newInstance(
1246 listenerClassName));
1247 }
1248
1249 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1250 }
1251 catch (Exception e) {
1252 _log.error(e);
1253 }
1254 }
1255 }
1256
1257 public void destroy() {
1258 EntityCacheUtil.removeCache(AnnouncementsFlagImpl.class.getName());
1259 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1260 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1261 }
1262
1263 @BeanReference(type = AnnouncementsDeliveryPersistence.class)
1264 protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1265 @BeanReference(type = AnnouncementsEntryPersistence.class)
1266 protected AnnouncementsEntryPersistence announcementsEntryPersistence;
1267 @BeanReference(type = AnnouncementsFlagPersistence.class)
1268 protected AnnouncementsFlagPersistence announcementsFlagPersistence;
1269 @BeanReference(type = ResourcePersistence.class)
1270 protected ResourcePersistence resourcePersistence;
1271 @BeanReference(type = UserPersistence.class)
1272 protected UserPersistence userPersistence;
1273 private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag";
1274 private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag WHERE ";
1275 private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag";
1276 private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag WHERE ";
1277 private static final String _FINDER_COLUMN_ENTRYID_ENTRYID_2 = "announcementsFlag.entryId = ?";
1278 private static final String _FINDER_COLUMN_U_E_V_USERID_2 = "announcementsFlag.userId = ? AND ";
1279 private static final String _FINDER_COLUMN_U_E_V_ENTRYID_2 = "announcementsFlag.entryId = ? AND ";
1280 private static final String _FINDER_COLUMN_U_E_V_VALUE_2 = "announcementsFlag.value = ?";
1281 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsFlag.";
1282 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsFlag exists with the primary key ";
1283 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsFlag exists with the key {";
1284 private static Log _log = LogFactoryUtil.getLog(AnnouncementsFlagPersistenceImpl.class);
1285 }