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 if (announcementsFlag.isCachedModel() ||
253 BatchSessionUtil.isEnabled()) {
254 Object staleObject = session.get(AnnouncementsFlagImpl.class,
255 announcementsFlag.getPrimaryKeyObj());
256
257 if (staleObject != null) {
258 session.evict(staleObject);
259 }
260 }
261
262 session.delete(announcementsFlag);
263
264 session.flush();
265 }
266 catch (Exception e) {
267 throw processException(e);
268 }
269 finally {
270 closeSession(session);
271 }
272
273 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
274
275 AnnouncementsFlagModelImpl announcementsFlagModelImpl = (AnnouncementsFlagModelImpl)announcementsFlag;
276
277 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V,
278 new Object[] {
279 new Long(announcementsFlagModelImpl.getOriginalUserId()),
280 new Long(announcementsFlagModelImpl.getOriginalEntryId()),
281 new Integer(announcementsFlagModelImpl.getOriginalValue())
282 });
283
284 EntityCacheUtil.removeResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
285 AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey());
286
287 return announcementsFlag;
288 }
289
290 public AnnouncementsFlag updateImpl(
291 com.liferay.portlet.announcements.model.AnnouncementsFlag announcementsFlag,
292 boolean merge) throws SystemException {
293 announcementsFlag = toUnwrappedModel(announcementsFlag);
294
295 boolean isNew = announcementsFlag.isNew();
296
297 AnnouncementsFlagModelImpl announcementsFlagModelImpl = (AnnouncementsFlagModelImpl)announcementsFlag;
298
299 Session session = null;
300
301 try {
302 session = openSession();
303
304 BatchSessionUtil.update(session, announcementsFlag, merge);
305
306 announcementsFlag.setNew(false);
307 }
308 catch (Exception e) {
309 throw processException(e);
310 }
311 finally {
312 closeSession(session);
313 }
314
315 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
316
317 EntityCacheUtil.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
318 AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey(),
319 announcementsFlag);
320
321 if (!isNew &&
322 ((announcementsFlag.getUserId() != announcementsFlagModelImpl.getOriginalUserId()) ||
323 (announcementsFlag.getEntryId() != announcementsFlagModelImpl.getOriginalEntryId()) ||
324 (announcementsFlag.getValue() != announcementsFlagModelImpl.getOriginalValue()))) {
325 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V,
326 new Object[] {
327 new Long(announcementsFlagModelImpl.getOriginalUserId()),
328 new Long(announcementsFlagModelImpl.getOriginalEntryId()),
329 new Integer(announcementsFlagModelImpl.getOriginalValue())
330 });
331 }
332
333 if (isNew ||
334 ((announcementsFlag.getUserId() != announcementsFlagModelImpl.getOriginalUserId()) ||
335 (announcementsFlag.getEntryId() != announcementsFlagModelImpl.getOriginalEntryId()) ||
336 (announcementsFlag.getValue() != announcementsFlagModelImpl.getOriginalValue()))) {
337 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
338 new Object[] {
339 new Long(announcementsFlag.getUserId()),
340 new Long(announcementsFlag.getEntryId()),
341 new Integer(announcementsFlag.getValue())
342 }, announcementsFlag);
343 }
344
345 return announcementsFlag;
346 }
347
348 protected AnnouncementsFlag toUnwrappedModel(
349 AnnouncementsFlag announcementsFlag) {
350 if (announcementsFlag instanceof AnnouncementsFlagImpl) {
351 return announcementsFlag;
352 }
353
354 AnnouncementsFlagImpl announcementsFlagImpl = new AnnouncementsFlagImpl();
355
356 announcementsFlagImpl.setNew(announcementsFlag.isNew());
357 announcementsFlagImpl.setPrimaryKey(announcementsFlag.getPrimaryKey());
358
359 announcementsFlagImpl.setFlagId(announcementsFlag.getFlagId());
360 announcementsFlagImpl.setUserId(announcementsFlag.getUserId());
361 announcementsFlagImpl.setCreateDate(announcementsFlag.getCreateDate());
362 announcementsFlagImpl.setEntryId(announcementsFlag.getEntryId());
363 announcementsFlagImpl.setValue(announcementsFlag.getValue());
364
365 return announcementsFlagImpl;
366 }
367
368
376 public AnnouncementsFlag findByPrimaryKey(Serializable primaryKey)
377 throws NoSuchModelException, SystemException {
378 return findByPrimaryKey(((Long)primaryKey).longValue());
379 }
380
381
389 public AnnouncementsFlag findByPrimaryKey(long flagId)
390 throws NoSuchFlagException, SystemException {
391 AnnouncementsFlag announcementsFlag = fetchByPrimaryKey(flagId);
392
393 if (announcementsFlag == null) {
394 if (_log.isWarnEnabled()) {
395 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + flagId);
396 }
397
398 throw new NoSuchFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
399 flagId);
400 }
401
402 return announcementsFlag;
403 }
404
405
412 public AnnouncementsFlag fetchByPrimaryKey(Serializable primaryKey)
413 throws SystemException {
414 return fetchByPrimaryKey(((Long)primaryKey).longValue());
415 }
416
417
424 public AnnouncementsFlag fetchByPrimaryKey(long flagId)
425 throws SystemException {
426 AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)EntityCacheUtil.getResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
427 AnnouncementsFlagImpl.class, flagId, this);
428
429 if (announcementsFlag == null) {
430 Session session = null;
431
432 try {
433 session = openSession();
434
435 announcementsFlag = (AnnouncementsFlag)session.get(AnnouncementsFlagImpl.class,
436 new Long(flagId));
437 }
438 catch (Exception e) {
439 throw processException(e);
440 }
441 finally {
442 if (announcementsFlag != null) {
443 cacheResult(announcementsFlag);
444 }
445
446 closeSession(session);
447 }
448 }
449
450 return announcementsFlag;
451 }
452
453
460 public List<AnnouncementsFlag> findByEntryId(long entryId)
461 throws SystemException {
462 return findByEntryId(entryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
463 }
464
465
478 public List<AnnouncementsFlag> findByEntryId(long entryId, int start,
479 int end) throws SystemException {
480 return findByEntryId(entryId, start, end, null);
481 }
482
483
497 public List<AnnouncementsFlag> findByEntryId(long entryId, int start,
498 int end, OrderByComparator orderByComparator) throws SystemException {
499 Object[] finderArgs = new Object[] {
500 entryId,
501
502 String.valueOf(start), String.valueOf(end),
503 String.valueOf(orderByComparator)
504 };
505
506 List<AnnouncementsFlag> list = (List<AnnouncementsFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ENTRYID,
507 finderArgs, this);
508
509 if (list == null) {
510 Session session = null;
511
512 try {
513 session = openSession();
514
515 StringBundler query = null;
516
517 if (orderByComparator != null) {
518 query = new StringBundler(3 +
519 (orderByComparator.getOrderByFields().length * 3));
520 }
521 else {
522 query = new StringBundler(3);
523 }
524
525 query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
526
527 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
528
529 if (orderByComparator != null) {
530 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
531 orderByComparator);
532 }
533
534 else {
535 query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
536 }
537
538 String sql = query.toString();
539
540 Query q = session.createQuery(sql);
541
542 QueryPos qPos = QueryPos.getInstance(q);
543
544 qPos.add(entryId);
545
546 list = (List<AnnouncementsFlag>)QueryUtil.list(q, getDialect(),
547 start, end);
548 }
549 catch (Exception e) {
550 throw processException(e);
551 }
552 finally {
553 if (list == null) {
554 list = new ArrayList<AnnouncementsFlag>();
555 }
556
557 cacheResult(list);
558
559 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ENTRYID,
560 finderArgs, list);
561
562 closeSession(session);
563 }
564 }
565
566 return list;
567 }
568
569
582 public AnnouncementsFlag findByEntryId_First(long entryId,
583 OrderByComparator orderByComparator)
584 throws NoSuchFlagException, SystemException {
585 List<AnnouncementsFlag> list = findByEntryId(entryId, 0, 1,
586 orderByComparator);
587
588 if (list.isEmpty()) {
589 StringBundler msg = new StringBundler(4);
590
591 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
592
593 msg.append("entryId=");
594 msg.append(entryId);
595
596 msg.append(StringPool.CLOSE_CURLY_BRACE);
597
598 throw new NoSuchFlagException(msg.toString());
599 }
600 else {
601 return list.get(0);
602 }
603 }
604
605
618 public AnnouncementsFlag findByEntryId_Last(long entryId,
619 OrderByComparator orderByComparator)
620 throws NoSuchFlagException, SystemException {
621 int count = countByEntryId(entryId);
622
623 List<AnnouncementsFlag> list = findByEntryId(entryId, count - 1, count,
624 orderByComparator);
625
626 if (list.isEmpty()) {
627 StringBundler msg = new StringBundler(4);
628
629 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
630
631 msg.append("entryId=");
632 msg.append(entryId);
633
634 msg.append(StringPool.CLOSE_CURLY_BRACE);
635
636 throw new NoSuchFlagException(msg.toString());
637 }
638 else {
639 return list.get(0);
640 }
641 }
642
643
657 public AnnouncementsFlag[] findByEntryId_PrevAndNext(long flagId,
658 long entryId, OrderByComparator orderByComparator)
659 throws NoSuchFlagException, SystemException {
660 AnnouncementsFlag announcementsFlag = findByPrimaryKey(flagId);
661
662 Session session = null;
663
664 try {
665 session = openSession();
666
667 AnnouncementsFlag[] array = new AnnouncementsFlagImpl[3];
668
669 array[0] = getByEntryId_PrevAndNext(session, announcementsFlag,
670 entryId, orderByComparator, true);
671
672 array[1] = announcementsFlag;
673
674 array[2] = getByEntryId_PrevAndNext(session, announcementsFlag,
675 entryId, orderByComparator, false);
676
677 return array;
678 }
679 catch (Exception e) {
680 throw processException(e);
681 }
682 finally {
683 closeSession(session);
684 }
685 }
686
687 protected AnnouncementsFlag getByEntryId_PrevAndNext(Session session,
688 AnnouncementsFlag announcementsFlag, long entryId,
689 OrderByComparator orderByComparator, boolean previous) {
690 StringBundler query = null;
691
692 if (orderByComparator != null) {
693 query = new StringBundler(6 +
694 (orderByComparator.getOrderByFields().length * 6));
695 }
696 else {
697 query = new StringBundler(3);
698 }
699
700 query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
701
702 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
703
704 if (orderByComparator != null) {
705 String[] orderByFields = orderByComparator.getOrderByFields();
706
707 if (orderByFields.length > 0) {
708 query.append(WHERE_AND);
709 }
710
711 for (int i = 0; i < orderByFields.length; i++) {
712 query.append(_ORDER_BY_ENTITY_ALIAS);
713 query.append(orderByFields[i]);
714
715 if ((i + 1) < orderByFields.length) {
716 if (orderByComparator.isAscending() ^ previous) {
717 query.append(WHERE_GREATER_THAN_HAS_NEXT);
718 }
719 else {
720 query.append(WHERE_LESSER_THAN_HAS_NEXT);
721 }
722 }
723 else {
724 if (orderByComparator.isAscending() ^ previous) {
725 query.append(WHERE_GREATER_THAN);
726 }
727 else {
728 query.append(WHERE_LESSER_THAN);
729 }
730 }
731 }
732
733 query.append(ORDER_BY_CLAUSE);
734
735 for (int i = 0; i < orderByFields.length; i++) {
736 query.append(_ORDER_BY_ENTITY_ALIAS);
737 query.append(orderByFields[i]);
738
739 if ((i + 1) < orderByFields.length) {
740 if (orderByComparator.isAscending() ^ previous) {
741 query.append(ORDER_BY_ASC_HAS_NEXT);
742 }
743 else {
744 query.append(ORDER_BY_DESC_HAS_NEXT);
745 }
746 }
747 else {
748 if (orderByComparator.isAscending() ^ previous) {
749 query.append(ORDER_BY_ASC);
750 }
751 else {
752 query.append(ORDER_BY_DESC);
753 }
754 }
755 }
756 }
757
758 else {
759 query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
760 }
761
762 String sql = query.toString();
763
764 Query q = session.createQuery(sql);
765
766 q.setFirstResult(0);
767 q.setMaxResults(2);
768
769 QueryPos qPos = QueryPos.getInstance(q);
770
771 qPos.add(entryId);
772
773 if (orderByComparator != null) {
774 Object[] values = orderByComparator.getOrderByValues(announcementsFlag);
775
776 for (Object value : values) {
777 qPos.add(value);
778 }
779 }
780
781 List<AnnouncementsFlag> list = q.list();
782
783 if (list.size() == 2) {
784 return list.get(1);
785 }
786 else {
787 return null;
788 }
789 }
790
791
801 public AnnouncementsFlag findByU_E_V(long userId, long entryId, int value)
802 throws NoSuchFlagException, SystemException {
803 AnnouncementsFlag announcementsFlag = fetchByU_E_V(userId, entryId,
804 value);
805
806 if (announcementsFlag == null) {
807 StringBundler msg = new StringBundler(8);
808
809 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
810
811 msg.append("userId=");
812 msg.append(userId);
813
814 msg.append(", entryId=");
815 msg.append(entryId);
816
817 msg.append(", value=");
818 msg.append(value);
819
820 msg.append(StringPool.CLOSE_CURLY_BRACE);
821
822 if (_log.isWarnEnabled()) {
823 _log.warn(msg.toString());
824 }
825
826 throw new NoSuchFlagException(msg.toString());
827 }
828
829 return announcementsFlag;
830 }
831
832
841 public AnnouncementsFlag fetchByU_E_V(long userId, long entryId, int value)
842 throws SystemException {
843 return fetchByU_E_V(userId, entryId, value, true);
844 }
845
846
855 public AnnouncementsFlag fetchByU_E_V(long userId, long entryId, int value,
856 boolean retrieveFromCache) throws SystemException {
857 Object[] finderArgs = new Object[] { userId, entryId, value };
858
859 Object result = null;
860
861 if (retrieveFromCache) {
862 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_E_V,
863 finderArgs, this);
864 }
865
866 if (result == null) {
867 Session session = null;
868
869 try {
870 session = openSession();
871
872 StringBundler query = new StringBundler(5);
873
874 query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
875
876 query.append(_FINDER_COLUMN_U_E_V_USERID_2);
877
878 query.append(_FINDER_COLUMN_U_E_V_ENTRYID_2);
879
880 query.append(_FINDER_COLUMN_U_E_V_VALUE_2);
881
882 query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
883
884 String sql = query.toString();
885
886 Query q = session.createQuery(sql);
887
888 QueryPos qPos = QueryPos.getInstance(q);
889
890 qPos.add(userId);
891
892 qPos.add(entryId);
893
894 qPos.add(value);
895
896 List<AnnouncementsFlag> list = q.list();
897
898 result = list;
899
900 AnnouncementsFlag announcementsFlag = null;
901
902 if (list.isEmpty()) {
903 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
904 finderArgs, list);
905 }
906 else {
907 announcementsFlag = list.get(0);
908
909 cacheResult(announcementsFlag);
910
911 if ((announcementsFlag.getUserId() != userId) ||
912 (announcementsFlag.getEntryId() != entryId) ||
913 (announcementsFlag.getValue() != value)) {
914 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
915 finderArgs, announcementsFlag);
916 }
917 }
918
919 return announcementsFlag;
920 }
921 catch (Exception e) {
922 throw processException(e);
923 }
924 finally {
925 if (result == null) {
926 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
927 finderArgs, new ArrayList<AnnouncementsFlag>());
928 }
929
930 closeSession(session);
931 }
932 }
933 else {
934 if (result instanceof List<?>) {
935 return null;
936 }
937 else {
938 return (AnnouncementsFlag)result;
939 }
940 }
941 }
942
943
949 public List<AnnouncementsFlag> findAll() throws SystemException {
950 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
951 }
952
953
965 public List<AnnouncementsFlag> findAll(int start, int end)
966 throws SystemException {
967 return findAll(start, end, null);
968 }
969
970
983 public List<AnnouncementsFlag> findAll(int start, int end,
984 OrderByComparator orderByComparator) throws SystemException {
985 Object[] finderArgs = new Object[] {
986 String.valueOf(start), String.valueOf(end),
987 String.valueOf(orderByComparator)
988 };
989
990 List<AnnouncementsFlag> list = (List<AnnouncementsFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
991 finderArgs, this);
992
993 if (list == null) {
994 Session session = null;
995
996 try {
997 session = openSession();
998
999 StringBundler query = null;
1000 String sql = null;
1001
1002 if (orderByComparator != null) {
1003 query = new StringBundler(2 +
1004 (orderByComparator.getOrderByFields().length * 3));
1005
1006 query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG);
1007
1008 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1009 orderByComparator);
1010
1011 sql = query.toString();
1012 }
1013 else {
1014 sql = _SQL_SELECT_ANNOUNCEMENTSFLAG.concat(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
1015 }
1016
1017 Query q = session.createQuery(sql);
1018
1019 if (orderByComparator == null) {
1020 list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1021 getDialect(), start, end, false);
1022
1023 Collections.sort(list);
1024 }
1025 else {
1026 list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1027 getDialect(), start, end);
1028 }
1029 }
1030 catch (Exception e) {
1031 throw processException(e);
1032 }
1033 finally {
1034 if (list == null) {
1035 list = new ArrayList<AnnouncementsFlag>();
1036 }
1037
1038 cacheResult(list);
1039
1040 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1041
1042 closeSession(session);
1043 }
1044 }
1045
1046 return list;
1047 }
1048
1049
1055 public void removeByEntryId(long entryId) throws SystemException {
1056 for (AnnouncementsFlag announcementsFlag : findByEntryId(entryId)) {
1057 remove(announcementsFlag);
1058 }
1059 }
1060
1061
1069 public void removeByU_E_V(long userId, long entryId, int value)
1070 throws NoSuchFlagException, SystemException {
1071 AnnouncementsFlag announcementsFlag = findByU_E_V(userId, entryId, value);
1072
1073 remove(announcementsFlag);
1074 }
1075
1076
1081 public void removeAll() throws SystemException {
1082 for (AnnouncementsFlag announcementsFlag : findAll()) {
1083 remove(announcementsFlag);
1084 }
1085 }
1086
1087
1094 public int countByEntryId(long entryId) throws SystemException {
1095 Object[] finderArgs = new Object[] { entryId };
1096
1097 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ENTRYID,
1098 finderArgs, this);
1099
1100 if (count == null) {
1101 Session session = null;
1102
1103 try {
1104 session = openSession();
1105
1106 StringBundler query = new StringBundler(2);
1107
1108 query.append(_SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE);
1109
1110 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
1111
1112 String sql = query.toString();
1113
1114 Query q = session.createQuery(sql);
1115
1116 QueryPos qPos = QueryPos.getInstance(q);
1117
1118 qPos.add(entryId);
1119
1120 count = (Long)q.uniqueResult();
1121 }
1122 catch (Exception e) {
1123 throw processException(e);
1124 }
1125 finally {
1126 if (count == null) {
1127 count = Long.valueOf(0);
1128 }
1129
1130 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ENTRYID,
1131 finderArgs, count);
1132
1133 closeSession(session);
1134 }
1135 }
1136
1137 return count.intValue();
1138 }
1139
1140
1149 public int countByU_E_V(long userId, long entryId, int value)
1150 throws SystemException {
1151 Object[] finderArgs = new Object[] { userId, entryId, value };
1152
1153 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_E_V,
1154 finderArgs, this);
1155
1156 if (count == null) {
1157 Session session = null;
1158
1159 try {
1160 session = openSession();
1161
1162 StringBundler query = new StringBundler(4);
1163
1164 query.append(_SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE);
1165
1166 query.append(_FINDER_COLUMN_U_E_V_USERID_2);
1167
1168 query.append(_FINDER_COLUMN_U_E_V_ENTRYID_2);
1169
1170 query.append(_FINDER_COLUMN_U_E_V_VALUE_2);
1171
1172 String sql = query.toString();
1173
1174 Query q = session.createQuery(sql);
1175
1176 QueryPos qPos = QueryPos.getInstance(q);
1177
1178 qPos.add(userId);
1179
1180 qPos.add(entryId);
1181
1182 qPos.add(value);
1183
1184 count = (Long)q.uniqueResult();
1185 }
1186 catch (Exception e) {
1187 throw processException(e);
1188 }
1189 finally {
1190 if (count == null) {
1191 count = Long.valueOf(0);
1192 }
1193
1194 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_E_V,
1195 finderArgs, count);
1196
1197 closeSession(session);
1198 }
1199 }
1200
1201 return count.intValue();
1202 }
1203
1204
1210 public int countAll() throws SystemException {
1211 Object[] finderArgs = new Object[0];
1212
1213 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1214 finderArgs, this);
1215
1216 if (count == null) {
1217 Session session = null;
1218
1219 try {
1220 session = openSession();
1221
1222 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSFLAG);
1223
1224 count = (Long)q.uniqueResult();
1225 }
1226 catch (Exception e) {
1227 throw processException(e);
1228 }
1229 finally {
1230 if (count == null) {
1231 count = Long.valueOf(0);
1232 }
1233
1234 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1235 count);
1236
1237 closeSession(session);
1238 }
1239 }
1240
1241 return count.intValue();
1242 }
1243
1244
1247 public void afterPropertiesSet() {
1248 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1249 com.liferay.portal.util.PropsUtil.get(
1250 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsFlag")));
1251
1252 if (listenerClassNames.length > 0) {
1253 try {
1254 List<ModelListener<AnnouncementsFlag>> listenersList = new ArrayList<ModelListener<AnnouncementsFlag>>();
1255
1256 for (String listenerClassName : listenerClassNames) {
1257 listenersList.add((ModelListener<AnnouncementsFlag>)InstanceFactory.newInstance(
1258 listenerClassName));
1259 }
1260
1261 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1262 }
1263 catch (Exception e) {
1264 _log.error(e);
1265 }
1266 }
1267 }
1268
1269 @BeanReference(type = AnnouncementsDeliveryPersistence.class)
1270 protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1271 @BeanReference(type = AnnouncementsEntryPersistence.class)
1272 protected AnnouncementsEntryPersistence announcementsEntryPersistence;
1273 @BeanReference(type = AnnouncementsFlagPersistence.class)
1274 protected AnnouncementsFlagPersistence announcementsFlagPersistence;
1275 @BeanReference(type = ResourcePersistence.class)
1276 protected ResourcePersistence resourcePersistence;
1277 @BeanReference(type = UserPersistence.class)
1278 protected UserPersistence userPersistence;
1279 private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag";
1280 private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag WHERE ";
1281 private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag";
1282 private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag WHERE ";
1283 private static final String _FINDER_COLUMN_ENTRYID_ENTRYID_2 = "announcementsFlag.entryId = ?";
1284 private static final String _FINDER_COLUMN_U_E_V_USERID_2 = "announcementsFlag.userId = ? AND ";
1285 private static final String _FINDER_COLUMN_U_E_V_ENTRYID_2 = "announcementsFlag.entryId = ? AND ";
1286 private static final String _FINDER_COLUMN_U_E_V_VALUE_2 = "announcementsFlag.value = ?";
1287 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsFlag.";
1288 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsFlag exists with the primary key ";
1289 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsFlag exists with the key {";
1290 private static Log _log = LogFactoryUtil.getLog(AnnouncementsFlagPersistenceImpl.class);
1291 }