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