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