1
22
23 package com.liferay.portlet.announcements.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.annotation.BeanReference;
27 import com.liferay.portal.kernel.cache.CacheRegistry;
28 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
29 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
30 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
31 import com.liferay.portal.kernel.dao.orm.FinderPath;
32 import com.liferay.portal.kernel.dao.orm.Query;
33 import com.liferay.portal.kernel.dao.orm.QueryPos;
34 import com.liferay.portal.kernel.dao.orm.QueryUtil;
35 import com.liferay.portal.kernel.dao.orm.Session;
36 import com.liferay.portal.kernel.log.Log;
37 import com.liferay.portal.kernel.log.LogFactoryUtil;
38 import com.liferay.portal.kernel.util.GetterUtil;
39 import com.liferay.portal.kernel.util.OrderByComparator;
40 import com.liferay.portal.kernel.util.StringPool;
41 import com.liferay.portal.kernel.util.StringUtil;
42 import com.liferay.portal.model.ModelListener;
43 import com.liferay.portal.service.persistence.BatchSessionUtil;
44 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
45
46 import com.liferay.portlet.announcements.NoSuchFlagException;
47 import com.liferay.portlet.announcements.model.AnnouncementsFlag;
48 import com.liferay.portlet.announcements.model.impl.AnnouncementsFlagImpl;
49 import com.liferay.portlet.announcements.model.impl.AnnouncementsFlagModelImpl;
50
51 import java.util.ArrayList;
52 import java.util.Collections;
53 import java.util.List;
54
55
61 public class AnnouncementsFlagPersistenceImpl extends BasePersistenceImpl
62 implements AnnouncementsFlagPersistence {
63 public static final String FINDER_CLASS_NAME_ENTITY = AnnouncementsFlagImpl.class.getName();
64 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
65 ".List";
66 public static final FinderPath FINDER_PATH_FIND_BY_ENTRYID = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
67 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
68 FINDER_CLASS_NAME_LIST, "findByEntryId",
69 new String[] { Long.class.getName() });
70 public static final FinderPath FINDER_PATH_FIND_BY_OBC_ENTRYID = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
71 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
72 FINDER_CLASS_NAME_LIST, "findByEntryId",
73 new String[] {
74 Long.class.getName(),
75
76 "java.lang.Integer", "java.lang.Integer",
77 "com.liferay.portal.kernel.util.OrderByComparator"
78 });
79 public static final FinderPath FINDER_PATH_COUNT_BY_ENTRYID = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
80 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
81 FINDER_CLASS_NAME_LIST, "countByEntryId",
82 new String[] { Long.class.getName() });
83 public static final FinderPath FINDER_PATH_FETCH_BY_U_E_V = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
84 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
85 FINDER_CLASS_NAME_ENTITY, "fetchByU_E_V",
86 new String[] {
87 Long.class.getName(), Long.class.getName(),
88 Integer.class.getName()
89 });
90 public static final FinderPath FINDER_PATH_COUNT_BY_U_E_V = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
91 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
92 FINDER_CLASS_NAME_LIST, "countByU_E_V",
93 new String[] {
94 Long.class.getName(), Long.class.getName(),
95 Integer.class.getName()
96 });
97 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
98 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
99 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
100 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
101 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
102 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
103
104 public void cacheResult(AnnouncementsFlag announcementsFlag) {
105 EntityCacheUtil.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
106 AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey(),
107 announcementsFlag);
108
109 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
110 new Object[] {
111 new Long(announcementsFlag.getUserId()),
112 new Long(announcementsFlag.getEntryId()),
113 new Integer(announcementsFlag.getValue())
114 }, announcementsFlag);
115 }
116
117 public void cacheResult(List<AnnouncementsFlag> announcementsFlags) {
118 for (AnnouncementsFlag announcementsFlag : announcementsFlags) {
119 if (EntityCacheUtil.getResult(
120 AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
121 AnnouncementsFlagImpl.class,
122 announcementsFlag.getPrimaryKey(), this) == null) {
123 cacheResult(announcementsFlag);
124 }
125 }
126 }
127
128 public void clearCache() {
129 CacheRegistry.clear(AnnouncementsFlagImpl.class.getName());
130 EntityCacheUtil.clearCache(AnnouncementsFlagImpl.class.getName());
131 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
132 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
133 }
134
135 public AnnouncementsFlag create(long flagId) {
136 AnnouncementsFlag announcementsFlag = new AnnouncementsFlagImpl();
137
138 announcementsFlag.setNew(true);
139 announcementsFlag.setPrimaryKey(flagId);
140
141 return announcementsFlag;
142 }
143
144 public AnnouncementsFlag remove(long flagId)
145 throws NoSuchFlagException, SystemException {
146 Session session = null;
147
148 try {
149 session = openSession();
150
151 AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)session.get(AnnouncementsFlagImpl.class,
152 new Long(flagId));
153
154 if (announcementsFlag == null) {
155 if (_log.isWarnEnabled()) {
156 _log.warn(
157 "No AnnouncementsFlag exists with the primary key " +
158 flagId);
159 }
160
161 throw new NoSuchFlagException(
162 "No AnnouncementsFlag exists with the primary key " +
163 flagId);
164 }
165
166 return remove(announcementsFlag);
167 }
168 catch (NoSuchFlagException nsee) {
169 throw nsee;
170 }
171 catch (Exception e) {
172 throw processException(e);
173 }
174 finally {
175 closeSession(session);
176 }
177 }
178
179 public AnnouncementsFlag remove(AnnouncementsFlag announcementsFlag)
180 throws SystemException {
181 for (ModelListener<AnnouncementsFlag> listener : listeners) {
182 listener.onBeforeRemove(announcementsFlag);
183 }
184
185 announcementsFlag = removeImpl(announcementsFlag);
186
187 for (ModelListener<AnnouncementsFlag> listener : listeners) {
188 listener.onAfterRemove(announcementsFlag);
189 }
190
191 return announcementsFlag;
192 }
193
194 protected AnnouncementsFlag removeImpl(AnnouncementsFlag announcementsFlag)
195 throws SystemException {
196 Session session = null;
197
198 try {
199 session = openSession();
200
201 if (announcementsFlag.isCachedModel() ||
202 BatchSessionUtil.isEnabled()) {
203 Object staleObject = session.get(AnnouncementsFlagImpl.class,
204 announcementsFlag.getPrimaryKeyObj());
205
206 if (staleObject != null) {
207 session.evict(staleObject);
208 }
209 }
210
211 session.delete(announcementsFlag);
212
213 session.flush();
214 }
215 catch (Exception e) {
216 throw processException(e);
217 }
218 finally {
219 closeSession(session);
220 }
221
222 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
223
224 AnnouncementsFlagModelImpl announcementsFlagModelImpl = (AnnouncementsFlagModelImpl)announcementsFlag;
225
226 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V,
227 new Object[] {
228 new Long(announcementsFlagModelImpl.getOriginalUserId()),
229 new Long(announcementsFlagModelImpl.getOriginalEntryId()),
230 new Integer(announcementsFlagModelImpl.getOriginalValue())
231 });
232
233 EntityCacheUtil.removeResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
234 AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey());
235
236 return announcementsFlag;
237 }
238
239
242 public AnnouncementsFlag update(AnnouncementsFlag announcementsFlag)
243 throws SystemException {
244 if (_log.isWarnEnabled()) {
245 _log.warn(
246 "Using the deprecated update(AnnouncementsFlag announcementsFlag) method. Use update(AnnouncementsFlag announcementsFlag, boolean merge) instead.");
247 }
248
249 return update(announcementsFlag, false);
250 }
251
252
265 public AnnouncementsFlag update(AnnouncementsFlag announcementsFlag,
266 boolean merge) throws SystemException {
267 boolean isNew = announcementsFlag.isNew();
268
269 for (ModelListener<AnnouncementsFlag> listener : listeners) {
270 if (isNew) {
271 listener.onBeforeCreate(announcementsFlag);
272 }
273 else {
274 listener.onBeforeUpdate(announcementsFlag);
275 }
276 }
277
278 announcementsFlag = updateImpl(announcementsFlag, merge);
279
280 for (ModelListener<AnnouncementsFlag> listener : listeners) {
281 if (isNew) {
282 listener.onAfterCreate(announcementsFlag);
283 }
284 else {
285 listener.onAfterUpdate(announcementsFlag);
286 }
287 }
288
289 return announcementsFlag;
290 }
291
292 public AnnouncementsFlag updateImpl(
293 com.liferay.portlet.announcements.model.AnnouncementsFlag announcementsFlag,
294 boolean merge) throws SystemException {
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 public AnnouncementsFlag findByPrimaryKey(long flagId)
349 throws NoSuchFlagException, SystemException {
350 AnnouncementsFlag announcementsFlag = fetchByPrimaryKey(flagId);
351
352 if (announcementsFlag == null) {
353 if (_log.isWarnEnabled()) {
354 _log.warn("No AnnouncementsFlag exists with the primary key " +
355 flagId);
356 }
357
358 throw new NoSuchFlagException(
359 "No AnnouncementsFlag exists with the primary key " + flagId);
360 }
361
362 return announcementsFlag;
363 }
364
365 public AnnouncementsFlag fetchByPrimaryKey(long flagId)
366 throws SystemException {
367 AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)EntityCacheUtil.getResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
368 AnnouncementsFlagImpl.class, flagId, this);
369
370 if (announcementsFlag == null) {
371 Session session = null;
372
373 try {
374 session = openSession();
375
376 announcementsFlag = (AnnouncementsFlag)session.get(AnnouncementsFlagImpl.class,
377 new Long(flagId));
378 }
379 catch (Exception e) {
380 throw processException(e);
381 }
382 finally {
383 if (announcementsFlag != null) {
384 cacheResult(announcementsFlag);
385 }
386
387 closeSession(session);
388 }
389 }
390
391 return announcementsFlag;
392 }
393
394 public List<AnnouncementsFlag> findByEntryId(long entryId)
395 throws SystemException {
396 Object[] finderArgs = new Object[] { new Long(entryId) };
397
398 List<AnnouncementsFlag> list = (List<AnnouncementsFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ENTRYID,
399 finderArgs, this);
400
401 if (list == null) {
402 Session session = null;
403
404 try {
405 session = openSession();
406
407 StringBuilder query = new StringBuilder();
408
409 query.append(
410 "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag WHERE ");
411
412 query.append("announcementsFlag.entryId = ?");
413
414 query.append(" ");
415
416 query.append("ORDER BY ");
417
418 query.append("announcementsFlag.userId ASC, ");
419 query.append("announcementsFlag.createDate ASC");
420
421 Query q = session.createQuery(query.toString());
422
423 QueryPos qPos = QueryPos.getInstance(q);
424
425 qPos.add(entryId);
426
427 list = q.list();
428 }
429 catch (Exception e) {
430 throw processException(e);
431 }
432 finally {
433 if (list == null) {
434 list = new ArrayList<AnnouncementsFlag>();
435 }
436
437 cacheResult(list);
438
439 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ENTRYID,
440 finderArgs, list);
441
442 closeSession(session);
443 }
444 }
445
446 return list;
447 }
448
449 public List<AnnouncementsFlag> findByEntryId(long entryId, int start,
450 int end) throws SystemException {
451 return findByEntryId(entryId, start, end, null);
452 }
453
454 public List<AnnouncementsFlag> findByEntryId(long entryId, int start,
455 int end, OrderByComparator obc) throws SystemException {
456 Object[] finderArgs = new Object[] {
457 new Long(entryId),
458
459 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
460 };
461
462 List<AnnouncementsFlag> list = (List<AnnouncementsFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_ENTRYID,
463 finderArgs, this);
464
465 if (list == null) {
466 Session session = null;
467
468 try {
469 session = openSession();
470
471 StringBuilder query = new StringBuilder();
472
473 query.append(
474 "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag WHERE ");
475
476 query.append("announcementsFlag.entryId = ?");
477
478 query.append(" ");
479
480 if (obc != null) {
481 query.append("ORDER BY ");
482
483 String[] orderByFields = obc.getOrderByFields();
484
485 for (int i = 0; i < orderByFields.length; i++) {
486 query.append("announcementsFlag.");
487 query.append(orderByFields[i]);
488
489 if (obc.isAscending()) {
490 query.append(" ASC");
491 }
492 else {
493 query.append(" DESC");
494 }
495
496 if ((i + 1) < orderByFields.length) {
497 query.append(", ");
498 }
499 }
500 }
501
502 else {
503 query.append("ORDER BY ");
504
505 query.append("announcementsFlag.userId ASC, ");
506 query.append("announcementsFlag.createDate ASC");
507 }
508
509 Query q = session.createQuery(query.toString());
510
511 QueryPos qPos = QueryPos.getInstance(q);
512
513 qPos.add(entryId);
514
515 list = (List<AnnouncementsFlag>)QueryUtil.list(q, getDialect(),
516 start, end);
517 }
518 catch (Exception e) {
519 throw processException(e);
520 }
521 finally {
522 if (list == null) {
523 list = new ArrayList<AnnouncementsFlag>();
524 }
525
526 cacheResult(list);
527
528 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_ENTRYID,
529 finderArgs, list);
530
531 closeSession(session);
532 }
533 }
534
535 return list;
536 }
537
538 public AnnouncementsFlag findByEntryId_First(long entryId,
539 OrderByComparator obc) throws NoSuchFlagException, SystemException {
540 List<AnnouncementsFlag> list = findByEntryId(entryId, 0, 1, obc);
541
542 if (list.isEmpty()) {
543 StringBuilder msg = new StringBuilder();
544
545 msg.append("No AnnouncementsFlag exists with the key {");
546
547 msg.append("entryId=" + entryId);
548
549 msg.append(StringPool.CLOSE_CURLY_BRACE);
550
551 throw new NoSuchFlagException(msg.toString());
552 }
553 else {
554 return list.get(0);
555 }
556 }
557
558 public AnnouncementsFlag findByEntryId_Last(long entryId,
559 OrderByComparator obc) throws NoSuchFlagException, SystemException {
560 int count = countByEntryId(entryId);
561
562 List<AnnouncementsFlag> list = findByEntryId(entryId, count - 1, count,
563 obc);
564
565 if (list.isEmpty()) {
566 StringBuilder msg = new StringBuilder();
567
568 msg.append("No AnnouncementsFlag exists with the key {");
569
570 msg.append("entryId=" + entryId);
571
572 msg.append(StringPool.CLOSE_CURLY_BRACE);
573
574 throw new NoSuchFlagException(msg.toString());
575 }
576 else {
577 return list.get(0);
578 }
579 }
580
581 public AnnouncementsFlag[] findByEntryId_PrevAndNext(long flagId,
582 long entryId, OrderByComparator obc)
583 throws NoSuchFlagException, SystemException {
584 AnnouncementsFlag announcementsFlag = findByPrimaryKey(flagId);
585
586 int count = countByEntryId(entryId);
587
588 Session session = null;
589
590 try {
591 session = openSession();
592
593 StringBuilder query = new StringBuilder();
594
595 query.append(
596 "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag WHERE ");
597
598 query.append("announcementsFlag.entryId = ?");
599
600 query.append(" ");
601
602 if (obc != null) {
603 query.append("ORDER BY ");
604
605 String[] orderByFields = obc.getOrderByFields();
606
607 for (int i = 0; i < orderByFields.length; i++) {
608 query.append("announcementsFlag.");
609 query.append(orderByFields[i]);
610
611 if (obc.isAscending()) {
612 query.append(" ASC");
613 }
614 else {
615 query.append(" DESC");
616 }
617
618 if ((i + 1) < orderByFields.length) {
619 query.append(", ");
620 }
621 }
622 }
623
624 else {
625 query.append("ORDER BY ");
626
627 query.append("announcementsFlag.userId ASC, ");
628 query.append("announcementsFlag.createDate ASC");
629 }
630
631 Query q = session.createQuery(query.toString());
632
633 QueryPos qPos = QueryPos.getInstance(q);
634
635 qPos.add(entryId);
636
637 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
638 announcementsFlag);
639
640 AnnouncementsFlag[] array = new AnnouncementsFlagImpl[3];
641
642 array[0] = (AnnouncementsFlag)objArray[0];
643 array[1] = (AnnouncementsFlag)objArray[1];
644 array[2] = (AnnouncementsFlag)objArray[2];
645
646 return array;
647 }
648 catch (Exception e) {
649 throw processException(e);
650 }
651 finally {
652 closeSession(session);
653 }
654 }
655
656 public AnnouncementsFlag findByU_E_V(long userId, long entryId, int value)
657 throws NoSuchFlagException, SystemException {
658 AnnouncementsFlag announcementsFlag = fetchByU_E_V(userId, entryId,
659 value);
660
661 if (announcementsFlag == null) {
662 StringBuilder msg = new StringBuilder();
663
664 msg.append("No AnnouncementsFlag exists with the key {");
665
666 msg.append("userId=" + userId);
667
668 msg.append(", ");
669 msg.append("entryId=" + entryId);
670
671 msg.append(", ");
672 msg.append("value=" + value);
673
674 msg.append(StringPool.CLOSE_CURLY_BRACE);
675
676 if (_log.isWarnEnabled()) {
677 _log.warn(msg.toString());
678 }
679
680 throw new NoSuchFlagException(msg.toString());
681 }
682
683 return announcementsFlag;
684 }
685
686 public AnnouncementsFlag fetchByU_E_V(long userId, long entryId, int value)
687 throws SystemException {
688 return fetchByU_E_V(userId, entryId, value, true);
689 }
690
691 public AnnouncementsFlag fetchByU_E_V(long userId, long entryId, int value,
692 boolean retrieveFromCache) throws SystemException {
693 Object[] finderArgs = new Object[] {
694 new Long(userId), new Long(entryId), new Integer(value)
695 };
696
697 Object result = null;
698
699 if (retrieveFromCache) {
700 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_E_V,
701 finderArgs, this);
702 }
703
704 if (result == null) {
705 Session session = null;
706
707 try {
708 session = openSession();
709
710 StringBuilder query = new StringBuilder();
711
712 query.append(
713 "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag WHERE ");
714
715 query.append("announcementsFlag.userId = ?");
716
717 query.append(" AND ");
718
719 query.append("announcementsFlag.entryId = ?");
720
721 query.append(" AND ");
722
723 query.append("announcementsFlag.value = ?");
724
725 query.append(" ");
726
727 query.append("ORDER BY ");
728
729 query.append("announcementsFlag.userId ASC, ");
730 query.append("announcementsFlag.createDate ASC");
731
732 Query q = session.createQuery(query.toString());
733
734 QueryPos qPos = QueryPos.getInstance(q);
735
736 qPos.add(userId);
737
738 qPos.add(entryId);
739
740 qPos.add(value);
741
742 List<AnnouncementsFlag> list = q.list();
743
744 result = list;
745
746 AnnouncementsFlag announcementsFlag = null;
747
748 if (list.isEmpty()) {
749 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
750 finderArgs, list);
751 }
752 else {
753 announcementsFlag = list.get(0);
754
755 cacheResult(announcementsFlag);
756
757 if ((announcementsFlag.getUserId() != userId) ||
758 (announcementsFlag.getEntryId() != entryId) ||
759 (announcementsFlag.getValue() != value)) {
760 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
761 finderArgs, announcementsFlag);
762 }
763 }
764
765 return announcementsFlag;
766 }
767 catch (Exception e) {
768 throw processException(e);
769 }
770 finally {
771 if (result == null) {
772 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
773 finderArgs, new ArrayList<AnnouncementsFlag>());
774 }
775
776 closeSession(session);
777 }
778 }
779 else {
780 if (result instanceof List) {
781 return null;
782 }
783 else {
784 return (AnnouncementsFlag)result;
785 }
786 }
787 }
788
789 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
790 throws SystemException {
791 Session session = null;
792
793 try {
794 session = openSession();
795
796 dynamicQuery.compile(session);
797
798 return dynamicQuery.list();
799 }
800 catch (Exception e) {
801 throw processException(e);
802 }
803 finally {
804 closeSession(session);
805 }
806 }
807
808 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
809 int start, int end) throws SystemException {
810 Session session = null;
811
812 try {
813 session = openSession();
814
815 dynamicQuery.setLimit(start, end);
816
817 dynamicQuery.compile(session);
818
819 return dynamicQuery.list();
820 }
821 catch (Exception e) {
822 throw processException(e);
823 }
824 finally {
825 closeSession(session);
826 }
827 }
828
829 public List<AnnouncementsFlag> findAll() throws SystemException {
830 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
831 }
832
833 public List<AnnouncementsFlag> findAll(int start, int end)
834 throws SystemException {
835 return findAll(start, end, null);
836 }
837
838 public List<AnnouncementsFlag> findAll(int start, int end,
839 OrderByComparator obc) throws SystemException {
840 Object[] finderArgs = new Object[] {
841 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
842 };
843
844 List<AnnouncementsFlag> list = (List<AnnouncementsFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
845 finderArgs, this);
846
847 if (list == null) {
848 Session session = null;
849
850 try {
851 session = openSession();
852
853 StringBuilder query = new StringBuilder();
854
855 query.append(
856 "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag ");
857
858 if (obc != null) {
859 query.append("ORDER BY ");
860
861 String[] orderByFields = obc.getOrderByFields();
862
863 for (int i = 0; i < orderByFields.length; i++) {
864 query.append("announcementsFlag.");
865 query.append(orderByFields[i]);
866
867 if (obc.isAscending()) {
868 query.append(" ASC");
869 }
870 else {
871 query.append(" DESC");
872 }
873
874 if ((i + 1) < orderByFields.length) {
875 query.append(", ");
876 }
877 }
878 }
879
880 else {
881 query.append("ORDER BY ");
882
883 query.append("announcementsFlag.userId ASC, ");
884 query.append("announcementsFlag.createDate ASC");
885 }
886
887 Query q = session.createQuery(query.toString());
888
889 if (obc == null) {
890 list = (List<AnnouncementsFlag>)QueryUtil.list(q,
891 getDialect(), start, end, false);
892
893 Collections.sort(list);
894 }
895 else {
896 list = (List<AnnouncementsFlag>)QueryUtil.list(q,
897 getDialect(), start, end);
898 }
899 }
900 catch (Exception e) {
901 throw processException(e);
902 }
903 finally {
904 if (list == null) {
905 list = new ArrayList<AnnouncementsFlag>();
906 }
907
908 cacheResult(list);
909
910 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
911
912 closeSession(session);
913 }
914 }
915
916 return list;
917 }
918
919 public void removeByEntryId(long entryId) throws SystemException {
920 for (AnnouncementsFlag announcementsFlag : findByEntryId(entryId)) {
921 remove(announcementsFlag);
922 }
923 }
924
925 public void removeByU_E_V(long userId, long entryId, int value)
926 throws NoSuchFlagException, SystemException {
927 AnnouncementsFlag announcementsFlag = findByU_E_V(userId, entryId, value);
928
929 remove(announcementsFlag);
930 }
931
932 public void removeAll() throws SystemException {
933 for (AnnouncementsFlag announcementsFlag : findAll()) {
934 remove(announcementsFlag);
935 }
936 }
937
938 public int countByEntryId(long entryId) throws SystemException {
939 Object[] finderArgs = new Object[] { new Long(entryId) };
940
941 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ENTRYID,
942 finderArgs, this);
943
944 if (count == null) {
945 Session session = null;
946
947 try {
948 session = openSession();
949
950 StringBuilder query = new StringBuilder();
951
952 query.append("SELECT COUNT(announcementsFlag) ");
953 query.append("FROM AnnouncementsFlag announcementsFlag WHERE ");
954
955 query.append("announcementsFlag.entryId = ?");
956
957 query.append(" ");
958
959 Query q = session.createQuery(query.toString());
960
961 QueryPos qPos = QueryPos.getInstance(q);
962
963 qPos.add(entryId);
964
965 count = (Long)q.uniqueResult();
966 }
967 catch (Exception e) {
968 throw processException(e);
969 }
970 finally {
971 if (count == null) {
972 count = Long.valueOf(0);
973 }
974
975 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ENTRYID,
976 finderArgs, count);
977
978 closeSession(session);
979 }
980 }
981
982 return count.intValue();
983 }
984
985 public int countByU_E_V(long userId, long entryId, int value)
986 throws SystemException {
987 Object[] finderArgs = new Object[] {
988 new Long(userId), new Long(entryId), new Integer(value)
989 };
990
991 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_E_V,
992 finderArgs, this);
993
994 if (count == null) {
995 Session session = null;
996
997 try {
998 session = openSession();
999
1000 StringBuilder query = new StringBuilder();
1001
1002 query.append("SELECT COUNT(announcementsFlag) ");
1003 query.append("FROM AnnouncementsFlag announcementsFlag WHERE ");
1004
1005 query.append("announcementsFlag.userId = ?");
1006
1007 query.append(" AND ");
1008
1009 query.append("announcementsFlag.entryId = ?");
1010
1011 query.append(" AND ");
1012
1013 query.append("announcementsFlag.value = ?");
1014
1015 query.append(" ");
1016
1017 Query q = session.createQuery(query.toString());
1018
1019 QueryPos qPos = QueryPos.getInstance(q);
1020
1021 qPos.add(userId);
1022
1023 qPos.add(entryId);
1024
1025 qPos.add(value);
1026
1027 count = (Long)q.uniqueResult();
1028 }
1029 catch (Exception e) {
1030 throw processException(e);
1031 }
1032 finally {
1033 if (count == null) {
1034 count = Long.valueOf(0);
1035 }
1036
1037 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_E_V,
1038 finderArgs, count);
1039
1040 closeSession(session);
1041 }
1042 }
1043
1044 return count.intValue();
1045 }
1046
1047 public int countAll() throws SystemException {
1048 Object[] finderArgs = new Object[0];
1049
1050 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1051 finderArgs, this);
1052
1053 if (count == null) {
1054 Session session = null;
1055
1056 try {
1057 session = openSession();
1058
1059 Query q = session.createQuery(
1060 "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag");
1061
1062 count = (Long)q.uniqueResult();
1063 }
1064 catch (Exception e) {
1065 throw processException(e);
1066 }
1067 finally {
1068 if (count == null) {
1069 count = Long.valueOf(0);
1070 }
1071
1072 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1073 count);
1074
1075 closeSession(session);
1076 }
1077 }
1078
1079 return count.intValue();
1080 }
1081
1082 public void afterPropertiesSet() {
1083 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1084 com.liferay.portal.util.PropsUtil.get(
1085 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsFlag")));
1086
1087 if (listenerClassNames.length > 0) {
1088 try {
1089 List<ModelListener<AnnouncementsFlag>> listenersList = new ArrayList<ModelListener<AnnouncementsFlag>>();
1090
1091 for (String listenerClassName : listenerClassNames) {
1092 listenersList.add((ModelListener<AnnouncementsFlag>)Class.forName(
1093 listenerClassName).newInstance());
1094 }
1095
1096 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1097 }
1098 catch (Exception e) {
1099 _log.error(e);
1100 }
1101 }
1102 }
1103
1104 @BeanReference(name = "com.liferay.portlet.announcements.service.persistence.AnnouncementsDeliveryPersistence.impl")
1105 protected com.liferay.portlet.announcements.service.persistence.AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1106 @BeanReference(name = "com.liferay.portlet.announcements.service.persistence.AnnouncementsEntryPersistence.impl")
1107 protected com.liferay.portlet.announcements.service.persistence.AnnouncementsEntryPersistence announcementsEntryPersistence;
1108 @BeanReference(name = "com.liferay.portlet.announcements.service.persistence.AnnouncementsFlagPersistence.impl")
1109 protected com.liferay.portlet.announcements.service.persistence.AnnouncementsFlagPersistence announcementsFlagPersistence;
1110 private static Log _log = LogFactoryUtil.getLog(AnnouncementsFlagPersistenceImpl.class);
1111}