001
014
015 package com.liferay.portlet.announcements.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.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.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.BatchSessionUtil;
039 import com.liferay.portal.service.persistence.ResourcePersistence;
040 import com.liferay.portal.service.persistence.UserPersistence;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.announcements.NoSuchFlagException;
044 import com.liferay.portlet.announcements.model.AnnouncementsFlag;
045 import com.liferay.portlet.announcements.model.impl.AnnouncementsFlagImpl;
046 import com.liferay.portlet.announcements.model.impl.AnnouncementsFlagModelImpl;
047
048 import java.io.Serializable;
049
050 import java.util.ArrayList;
051 import java.util.Collections;
052 import java.util.List;
053
054
066 public class AnnouncementsFlagPersistenceImpl extends BasePersistenceImpl<AnnouncementsFlag>
067 implements AnnouncementsFlagPersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = AnnouncementsFlagImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ENTRYID = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
079 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
080 AnnouncementsFlagImpl.class,
081 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByEntryId",
082 new String[] {
083 Long.class.getName(),
084
085 "java.lang.Integer", "java.lang.Integer",
086 "com.liferay.portal.kernel.util.OrderByComparator"
087 });
088 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID =
089 new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
090 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
091 AnnouncementsFlagImpl.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByEntryId",
093 new String[] { Long.class.getName() },
094 AnnouncementsFlagModelImpl.ENTRYID_COLUMN_BITMASK);
095 public static final FinderPath FINDER_PATH_COUNT_BY_ENTRYID = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
096 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByEntryId",
098 new String[] { Long.class.getName() });
099 public static final FinderPath FINDER_PATH_FETCH_BY_U_E_V = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
100 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
101 AnnouncementsFlagImpl.class, FINDER_CLASS_NAME_ENTITY,
102 "fetchByU_E_V",
103 new String[] {
104 Long.class.getName(), Long.class.getName(),
105 Integer.class.getName()
106 },
107 AnnouncementsFlagModelImpl.USERID_COLUMN_BITMASK |
108 AnnouncementsFlagModelImpl.ENTRYID_COLUMN_BITMASK |
109 AnnouncementsFlagModelImpl.VALUE_COLUMN_BITMASK);
110 public static final FinderPath FINDER_PATH_COUNT_BY_U_E_V = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
111 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
112 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_E_V",
113 new String[] {
114 Long.class.getName(), Long.class.getName(),
115 Integer.class.getName()
116 });
117 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
118 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
119 AnnouncementsFlagImpl.class,
120 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
121 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
122 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED,
123 AnnouncementsFlagImpl.class,
124 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
125 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
126 AnnouncementsFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
127 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
128
129
134 public void cacheResult(AnnouncementsFlag announcementsFlag) {
135 EntityCacheUtil.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
136 AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey(),
137 announcementsFlag);
138
139 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
140 new Object[] {
141 Long.valueOf(announcementsFlag.getUserId()),
142 Long.valueOf(announcementsFlag.getEntryId()),
143 Integer.valueOf(announcementsFlag.getValue())
144 }, announcementsFlag);
145
146 announcementsFlag.resetOriginalValues();
147 }
148
149
154 public void cacheResult(List<AnnouncementsFlag> announcementsFlags) {
155 for (AnnouncementsFlag announcementsFlag : announcementsFlags) {
156 if (EntityCacheUtil.getResult(
157 AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
158 AnnouncementsFlagImpl.class,
159 announcementsFlag.getPrimaryKey()) == null) {
160 cacheResult(announcementsFlag);
161 }
162 else {
163 announcementsFlag.resetOriginalValues();
164 }
165 }
166 }
167
168
175 @Override
176 public void clearCache() {
177 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
178 CacheRegistryUtil.clear(AnnouncementsFlagImpl.class.getName());
179 }
180
181 EntityCacheUtil.clearCache(AnnouncementsFlagImpl.class.getName());
182
183 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
184 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
185 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
186 }
187
188
195 @Override
196 public void clearCache(AnnouncementsFlag announcementsFlag) {
197 EntityCacheUtil.removeResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
198 AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey());
199
200 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
201 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
202
203 clearUniqueFindersCache(announcementsFlag);
204 }
205
206 @Override
207 public void clearCache(List<AnnouncementsFlag> announcementsFlags) {
208 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
209 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
210
211 for (AnnouncementsFlag announcementsFlag : announcementsFlags) {
212 EntityCacheUtil.removeResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
213 AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey());
214
215 clearUniqueFindersCache(announcementsFlag);
216 }
217 }
218
219 protected void cacheUniqueFindersCache(AnnouncementsFlag announcementsFlag) {
220 if (announcementsFlag.isNew()) {
221 Object[] args = new Object[] {
222 Long.valueOf(announcementsFlag.getUserId()),
223 Long.valueOf(announcementsFlag.getEntryId()),
224 Integer.valueOf(announcementsFlag.getValue())
225 };
226
227 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_E_V, args,
228 Long.valueOf(1));
229 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V, args,
230 announcementsFlag);
231 }
232 else {
233 AnnouncementsFlagModelImpl announcementsFlagModelImpl = (AnnouncementsFlagModelImpl)announcementsFlag;
234
235 if ((announcementsFlagModelImpl.getColumnBitmask() &
236 FINDER_PATH_FETCH_BY_U_E_V.getColumnBitmask()) != 0) {
237 Object[] args = new Object[] {
238 Long.valueOf(announcementsFlag.getUserId()),
239 Long.valueOf(announcementsFlag.getEntryId()),
240 Integer.valueOf(announcementsFlag.getValue())
241 };
242
243 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_E_V, args,
244 Long.valueOf(1));
245 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V, args,
246 announcementsFlag);
247 }
248 }
249 }
250
251 protected void clearUniqueFindersCache(AnnouncementsFlag announcementsFlag) {
252 AnnouncementsFlagModelImpl announcementsFlagModelImpl = (AnnouncementsFlagModelImpl)announcementsFlag;
253
254 Object[] args = new Object[] {
255 Long.valueOf(announcementsFlag.getUserId()),
256 Long.valueOf(announcementsFlag.getEntryId()),
257 Integer.valueOf(announcementsFlag.getValue())
258 };
259
260 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_E_V, args);
261 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V, args);
262
263 if ((announcementsFlagModelImpl.getColumnBitmask() &
264 FINDER_PATH_FETCH_BY_U_E_V.getColumnBitmask()) != 0) {
265 args = new Object[] {
266 Long.valueOf(announcementsFlagModelImpl.getOriginalUserId()),
267 Long.valueOf(announcementsFlagModelImpl.getOriginalEntryId()),
268 Integer.valueOf(announcementsFlagModelImpl.getOriginalValue())
269 };
270
271 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_E_V, args);
272 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V, args);
273 }
274 }
275
276
282 public AnnouncementsFlag create(long flagId) {
283 AnnouncementsFlag announcementsFlag = new AnnouncementsFlagImpl();
284
285 announcementsFlag.setNew(true);
286 announcementsFlag.setPrimaryKey(flagId);
287
288 return announcementsFlag;
289 }
290
291
299 public AnnouncementsFlag remove(long flagId)
300 throws NoSuchFlagException, SystemException {
301 return remove(Long.valueOf(flagId));
302 }
303
304
312 @Override
313 public AnnouncementsFlag remove(Serializable primaryKey)
314 throws NoSuchFlagException, SystemException {
315 Session session = null;
316
317 try {
318 session = openSession();
319
320 AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)session.get(AnnouncementsFlagImpl.class,
321 primaryKey);
322
323 if (announcementsFlag == null) {
324 if (_log.isWarnEnabled()) {
325 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
326 }
327
328 throw new NoSuchFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
329 primaryKey);
330 }
331
332 return remove(announcementsFlag);
333 }
334 catch (NoSuchFlagException nsee) {
335 throw nsee;
336 }
337 catch (Exception e) {
338 throw processException(e);
339 }
340 finally {
341 closeSession(session);
342 }
343 }
344
345 @Override
346 protected AnnouncementsFlag removeImpl(AnnouncementsFlag announcementsFlag)
347 throws SystemException {
348 announcementsFlag = toUnwrappedModel(announcementsFlag);
349
350 Session session = null;
351
352 try {
353 session = openSession();
354
355 BatchSessionUtil.delete(session, announcementsFlag);
356 }
357 catch (Exception e) {
358 throw processException(e);
359 }
360 finally {
361 closeSession(session);
362 }
363
364 clearCache(announcementsFlag);
365
366 return announcementsFlag;
367 }
368
369 @Override
370 public AnnouncementsFlag updateImpl(
371 com.liferay.portlet.announcements.model.AnnouncementsFlag announcementsFlag,
372 boolean merge) throws SystemException {
373 announcementsFlag = toUnwrappedModel(announcementsFlag);
374
375 boolean isNew = announcementsFlag.isNew();
376
377 AnnouncementsFlagModelImpl announcementsFlagModelImpl = (AnnouncementsFlagModelImpl)announcementsFlag;
378
379 Session session = null;
380
381 try {
382 session = openSession();
383
384 BatchSessionUtil.update(session, announcementsFlag, merge);
385
386 announcementsFlag.setNew(false);
387 }
388 catch (Exception e) {
389 throw processException(e);
390 }
391 finally {
392 closeSession(session);
393 }
394
395 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
396
397 if (isNew || !AnnouncementsFlagModelImpl.COLUMN_BITMASK_ENABLED) {
398 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
399 }
400
401 else {
402 if ((announcementsFlagModelImpl.getColumnBitmask() &
403 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID.getColumnBitmask()) != 0) {
404 Object[] args = new Object[] {
405 Long.valueOf(announcementsFlagModelImpl.getOriginalEntryId())
406 };
407
408 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
409 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
410 args);
411
412 args = new Object[] {
413 Long.valueOf(announcementsFlagModelImpl.getEntryId())
414 };
415
416 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ENTRYID, args);
417 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID,
418 args);
419 }
420 }
421
422 EntityCacheUtil.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
423 AnnouncementsFlagImpl.class, announcementsFlag.getPrimaryKey(),
424 announcementsFlag);
425
426 clearUniqueFindersCache(announcementsFlag);
427 cacheUniqueFindersCache(announcementsFlag);
428
429 return announcementsFlag;
430 }
431
432 protected AnnouncementsFlag toUnwrappedModel(
433 AnnouncementsFlag announcementsFlag) {
434 if (announcementsFlag instanceof AnnouncementsFlagImpl) {
435 return announcementsFlag;
436 }
437
438 AnnouncementsFlagImpl announcementsFlagImpl = new AnnouncementsFlagImpl();
439
440 announcementsFlagImpl.setNew(announcementsFlag.isNew());
441 announcementsFlagImpl.setPrimaryKey(announcementsFlag.getPrimaryKey());
442
443 announcementsFlagImpl.setFlagId(announcementsFlag.getFlagId());
444 announcementsFlagImpl.setUserId(announcementsFlag.getUserId());
445 announcementsFlagImpl.setCreateDate(announcementsFlag.getCreateDate());
446 announcementsFlagImpl.setEntryId(announcementsFlag.getEntryId());
447 announcementsFlagImpl.setValue(announcementsFlag.getValue());
448
449 return announcementsFlagImpl;
450 }
451
452
460 @Override
461 public AnnouncementsFlag findByPrimaryKey(Serializable primaryKey)
462 throws NoSuchModelException, SystemException {
463 return findByPrimaryKey(((Long)primaryKey).longValue());
464 }
465
466
474 public AnnouncementsFlag findByPrimaryKey(long flagId)
475 throws NoSuchFlagException, SystemException {
476 AnnouncementsFlag announcementsFlag = fetchByPrimaryKey(flagId);
477
478 if (announcementsFlag == null) {
479 if (_log.isWarnEnabled()) {
480 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + flagId);
481 }
482
483 throw new NoSuchFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
484 flagId);
485 }
486
487 return announcementsFlag;
488 }
489
490
497 @Override
498 public AnnouncementsFlag fetchByPrimaryKey(Serializable primaryKey)
499 throws SystemException {
500 return fetchByPrimaryKey(((Long)primaryKey).longValue());
501 }
502
503
510 public AnnouncementsFlag fetchByPrimaryKey(long flagId)
511 throws SystemException {
512 AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)EntityCacheUtil.getResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
513 AnnouncementsFlagImpl.class, flagId);
514
515 if (announcementsFlag == _nullAnnouncementsFlag) {
516 return null;
517 }
518
519 if (announcementsFlag == null) {
520 Session session = null;
521
522 boolean hasException = false;
523
524 try {
525 session = openSession();
526
527 announcementsFlag = (AnnouncementsFlag)session.get(AnnouncementsFlagImpl.class,
528 Long.valueOf(flagId));
529 }
530 catch (Exception e) {
531 hasException = true;
532
533 throw processException(e);
534 }
535 finally {
536 if (announcementsFlag != null) {
537 cacheResult(announcementsFlag);
538 }
539 else if (!hasException) {
540 EntityCacheUtil.putResult(AnnouncementsFlagModelImpl.ENTITY_CACHE_ENABLED,
541 AnnouncementsFlagImpl.class, flagId,
542 _nullAnnouncementsFlag);
543 }
544
545 closeSession(session);
546 }
547 }
548
549 return announcementsFlag;
550 }
551
552
559 public List<AnnouncementsFlag> findByEntryId(long entryId)
560 throws SystemException {
561 return findByEntryId(entryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
562 }
563
564
577 public List<AnnouncementsFlag> findByEntryId(long entryId, int start,
578 int end) throws SystemException {
579 return findByEntryId(entryId, start, end, null);
580 }
581
582
596 public List<AnnouncementsFlag> findByEntryId(long entryId, int start,
597 int end, OrderByComparator orderByComparator) throws SystemException {
598 FinderPath finderPath = null;
599 Object[] finderArgs = null;
600
601 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
602 (orderByComparator == null)) {
603 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ENTRYID;
604 finderArgs = new Object[] { entryId };
605 }
606 else {
607 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ENTRYID;
608 finderArgs = new Object[] { entryId, start, end, orderByComparator };
609 }
610
611 List<AnnouncementsFlag> list = (List<AnnouncementsFlag>)FinderCacheUtil.getResult(finderPath,
612 finderArgs, this);
613
614 if ((list != null) && !list.isEmpty()) {
615 for (AnnouncementsFlag announcementsFlag : list) {
616 if ((entryId != announcementsFlag.getEntryId())) {
617 list = null;
618
619 break;
620 }
621 }
622 }
623
624 if (list == null) {
625 StringBundler query = null;
626
627 if (orderByComparator != null) {
628 query = new StringBundler(3 +
629 (orderByComparator.getOrderByFields().length * 3));
630 }
631 else {
632 query = new StringBundler(3);
633 }
634
635 query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
636
637 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
638
639 if (orderByComparator != null) {
640 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
641 orderByComparator);
642 }
643
644 else {
645 query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
646 }
647
648 String sql = query.toString();
649
650 Session session = null;
651
652 try {
653 session = openSession();
654
655 Query q = session.createQuery(sql);
656
657 QueryPos qPos = QueryPos.getInstance(q);
658
659 qPos.add(entryId);
660
661 list = (List<AnnouncementsFlag>)QueryUtil.list(q, getDialect(),
662 start, end);
663 }
664 catch (Exception e) {
665 throw processException(e);
666 }
667 finally {
668 if (list == null) {
669 FinderCacheUtil.removeResult(finderPath, finderArgs);
670 }
671 else {
672 cacheResult(list);
673
674 FinderCacheUtil.putResult(finderPath, finderArgs, list);
675 }
676
677 closeSession(session);
678 }
679 }
680
681 return list;
682 }
683
684
693 public AnnouncementsFlag findByEntryId_First(long entryId,
694 OrderByComparator orderByComparator)
695 throws NoSuchFlagException, SystemException {
696 AnnouncementsFlag announcementsFlag = fetchByEntryId_First(entryId,
697 orderByComparator);
698
699 if (announcementsFlag != null) {
700 return announcementsFlag;
701 }
702
703 StringBundler msg = new StringBundler(4);
704
705 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
706
707 msg.append("entryId=");
708 msg.append(entryId);
709
710 msg.append(StringPool.CLOSE_CURLY_BRACE);
711
712 throw new NoSuchFlagException(msg.toString());
713 }
714
715
723 public AnnouncementsFlag fetchByEntryId_First(long entryId,
724 OrderByComparator orderByComparator) throws SystemException {
725 List<AnnouncementsFlag> list = findByEntryId(entryId, 0, 1,
726 orderByComparator);
727
728 if (!list.isEmpty()) {
729 return list.get(0);
730 }
731
732 return null;
733 }
734
735
744 public AnnouncementsFlag findByEntryId_Last(long entryId,
745 OrderByComparator orderByComparator)
746 throws NoSuchFlagException, SystemException {
747 AnnouncementsFlag announcementsFlag = fetchByEntryId_Last(entryId,
748 orderByComparator);
749
750 if (announcementsFlag != null) {
751 return announcementsFlag;
752 }
753
754 StringBundler msg = new StringBundler(4);
755
756 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
757
758 msg.append("entryId=");
759 msg.append(entryId);
760
761 msg.append(StringPool.CLOSE_CURLY_BRACE);
762
763 throw new NoSuchFlagException(msg.toString());
764 }
765
766
774 public AnnouncementsFlag fetchByEntryId_Last(long entryId,
775 OrderByComparator orderByComparator) throws SystemException {
776 int count = countByEntryId(entryId);
777
778 List<AnnouncementsFlag> list = findByEntryId(entryId, count - 1, count,
779 orderByComparator);
780
781 if (!list.isEmpty()) {
782 return list.get(0);
783 }
784
785 return null;
786 }
787
788
798 public AnnouncementsFlag[] findByEntryId_PrevAndNext(long flagId,
799 long entryId, OrderByComparator orderByComparator)
800 throws NoSuchFlagException, SystemException {
801 AnnouncementsFlag announcementsFlag = findByPrimaryKey(flagId);
802
803 Session session = null;
804
805 try {
806 session = openSession();
807
808 AnnouncementsFlag[] array = new AnnouncementsFlagImpl[3];
809
810 array[0] = getByEntryId_PrevAndNext(session, announcementsFlag,
811 entryId, orderByComparator, true);
812
813 array[1] = announcementsFlag;
814
815 array[2] = getByEntryId_PrevAndNext(session, announcementsFlag,
816 entryId, orderByComparator, false);
817
818 return array;
819 }
820 catch (Exception e) {
821 throw processException(e);
822 }
823 finally {
824 closeSession(session);
825 }
826 }
827
828 protected AnnouncementsFlag getByEntryId_PrevAndNext(Session session,
829 AnnouncementsFlag announcementsFlag, long entryId,
830 OrderByComparator orderByComparator, boolean previous) {
831 StringBundler query = null;
832
833 if (orderByComparator != null) {
834 query = new StringBundler(6 +
835 (orderByComparator.getOrderByFields().length * 6));
836 }
837 else {
838 query = new StringBundler(3);
839 }
840
841 query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
842
843 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
844
845 if (orderByComparator != null) {
846 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
847
848 if (orderByConditionFields.length > 0) {
849 query.append(WHERE_AND);
850 }
851
852 for (int i = 0; i < orderByConditionFields.length; i++) {
853 query.append(_ORDER_BY_ENTITY_ALIAS);
854 query.append(orderByConditionFields[i]);
855
856 if ((i + 1) < orderByConditionFields.length) {
857 if (orderByComparator.isAscending() ^ previous) {
858 query.append(WHERE_GREATER_THAN_HAS_NEXT);
859 }
860 else {
861 query.append(WHERE_LESSER_THAN_HAS_NEXT);
862 }
863 }
864 else {
865 if (orderByComparator.isAscending() ^ previous) {
866 query.append(WHERE_GREATER_THAN);
867 }
868 else {
869 query.append(WHERE_LESSER_THAN);
870 }
871 }
872 }
873
874 query.append(ORDER_BY_CLAUSE);
875
876 String[] orderByFields = orderByComparator.getOrderByFields();
877
878 for (int i = 0; i < orderByFields.length; i++) {
879 query.append(_ORDER_BY_ENTITY_ALIAS);
880 query.append(orderByFields[i]);
881
882 if ((i + 1) < orderByFields.length) {
883 if (orderByComparator.isAscending() ^ previous) {
884 query.append(ORDER_BY_ASC_HAS_NEXT);
885 }
886 else {
887 query.append(ORDER_BY_DESC_HAS_NEXT);
888 }
889 }
890 else {
891 if (orderByComparator.isAscending() ^ previous) {
892 query.append(ORDER_BY_ASC);
893 }
894 else {
895 query.append(ORDER_BY_DESC);
896 }
897 }
898 }
899 }
900
901 else {
902 query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
903 }
904
905 String sql = query.toString();
906
907 Query q = session.createQuery(sql);
908
909 q.setFirstResult(0);
910 q.setMaxResults(2);
911
912 QueryPos qPos = QueryPos.getInstance(q);
913
914 qPos.add(entryId);
915
916 if (orderByComparator != null) {
917 Object[] values = orderByComparator.getOrderByConditionValues(announcementsFlag);
918
919 for (Object value : values) {
920 qPos.add(value);
921 }
922 }
923
924 List<AnnouncementsFlag> list = q.list();
925
926 if (list.size() == 2) {
927 return list.get(1);
928 }
929 else {
930 return null;
931 }
932 }
933
934
944 public AnnouncementsFlag findByU_E_V(long userId, long entryId, int value)
945 throws NoSuchFlagException, SystemException {
946 AnnouncementsFlag announcementsFlag = fetchByU_E_V(userId, entryId,
947 value);
948
949 if (announcementsFlag == null) {
950 StringBundler msg = new StringBundler(8);
951
952 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
953
954 msg.append("userId=");
955 msg.append(userId);
956
957 msg.append(", entryId=");
958 msg.append(entryId);
959
960 msg.append(", value=");
961 msg.append(value);
962
963 msg.append(StringPool.CLOSE_CURLY_BRACE);
964
965 if (_log.isWarnEnabled()) {
966 _log.warn(msg.toString());
967 }
968
969 throw new NoSuchFlagException(msg.toString());
970 }
971
972 return announcementsFlag;
973 }
974
975
984 public AnnouncementsFlag fetchByU_E_V(long userId, long entryId, int value)
985 throws SystemException {
986 return fetchByU_E_V(userId, entryId, value, true);
987 }
988
989
999 public AnnouncementsFlag fetchByU_E_V(long userId, long entryId, int value,
1000 boolean retrieveFromCache) throws SystemException {
1001 Object[] finderArgs = new Object[] { userId, entryId, value };
1002
1003 Object result = null;
1004
1005 if (retrieveFromCache) {
1006 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_E_V,
1007 finderArgs, this);
1008 }
1009
1010 if (result instanceof AnnouncementsFlag) {
1011 AnnouncementsFlag announcementsFlag = (AnnouncementsFlag)result;
1012
1013 if ((userId != announcementsFlag.getUserId()) ||
1014 (entryId != announcementsFlag.getEntryId()) ||
1015 (value != announcementsFlag.getValue())) {
1016 result = null;
1017 }
1018 }
1019
1020 if (result == null) {
1021 StringBundler query = new StringBundler(5);
1022
1023 query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE);
1024
1025 query.append(_FINDER_COLUMN_U_E_V_USERID_2);
1026
1027 query.append(_FINDER_COLUMN_U_E_V_ENTRYID_2);
1028
1029 query.append(_FINDER_COLUMN_U_E_V_VALUE_2);
1030
1031 query.append(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
1032
1033 String sql = query.toString();
1034
1035 Session session = null;
1036
1037 try {
1038 session = openSession();
1039
1040 Query q = session.createQuery(sql);
1041
1042 QueryPos qPos = QueryPos.getInstance(q);
1043
1044 qPos.add(userId);
1045
1046 qPos.add(entryId);
1047
1048 qPos.add(value);
1049
1050 List<AnnouncementsFlag> list = q.list();
1051
1052 result = list;
1053
1054 AnnouncementsFlag announcementsFlag = null;
1055
1056 if (list.isEmpty()) {
1057 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
1058 finderArgs, list);
1059 }
1060 else {
1061 announcementsFlag = list.get(0);
1062
1063 cacheResult(announcementsFlag);
1064
1065 if ((announcementsFlag.getUserId() != userId) ||
1066 (announcementsFlag.getEntryId() != entryId) ||
1067 (announcementsFlag.getValue() != value)) {
1068 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_E_V,
1069 finderArgs, announcementsFlag);
1070 }
1071 }
1072
1073 return announcementsFlag;
1074 }
1075 catch (Exception e) {
1076 throw processException(e);
1077 }
1078 finally {
1079 if (result == null) {
1080 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_E_V,
1081 finderArgs);
1082 }
1083
1084 closeSession(session);
1085 }
1086 }
1087 else {
1088 if (result instanceof List<?>) {
1089 return null;
1090 }
1091 else {
1092 return (AnnouncementsFlag)result;
1093 }
1094 }
1095 }
1096
1097
1103 public List<AnnouncementsFlag> findAll() throws SystemException {
1104 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1105 }
1106
1107
1119 public List<AnnouncementsFlag> findAll(int start, int end)
1120 throws SystemException {
1121 return findAll(start, end, null);
1122 }
1123
1124
1137 public List<AnnouncementsFlag> findAll(int start, int end,
1138 OrderByComparator orderByComparator) throws SystemException {
1139 FinderPath finderPath = null;
1140 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1141
1142 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1143 (orderByComparator == null)) {
1144 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1145 finderArgs = FINDER_ARGS_EMPTY;
1146 }
1147 else {
1148 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1149 finderArgs = new Object[] { start, end, orderByComparator };
1150 }
1151
1152 List<AnnouncementsFlag> list = (List<AnnouncementsFlag>)FinderCacheUtil.getResult(finderPath,
1153 finderArgs, this);
1154
1155 if (list == null) {
1156 StringBundler query = null;
1157 String sql = null;
1158
1159 if (orderByComparator != null) {
1160 query = new StringBundler(2 +
1161 (orderByComparator.getOrderByFields().length * 3));
1162
1163 query.append(_SQL_SELECT_ANNOUNCEMENTSFLAG);
1164
1165 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1166 orderByComparator);
1167
1168 sql = query.toString();
1169 }
1170 else {
1171 sql = _SQL_SELECT_ANNOUNCEMENTSFLAG.concat(AnnouncementsFlagModelImpl.ORDER_BY_JPQL);
1172 }
1173
1174 Session session = null;
1175
1176 try {
1177 session = openSession();
1178
1179 Query q = session.createQuery(sql);
1180
1181 if (orderByComparator == null) {
1182 list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1183 getDialect(), start, end, false);
1184
1185 Collections.sort(list);
1186 }
1187 else {
1188 list = (List<AnnouncementsFlag>)QueryUtil.list(q,
1189 getDialect(), start, end);
1190 }
1191 }
1192 catch (Exception e) {
1193 throw processException(e);
1194 }
1195 finally {
1196 if (list == null) {
1197 FinderCacheUtil.removeResult(finderPath, finderArgs);
1198 }
1199 else {
1200 cacheResult(list);
1201
1202 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1203 }
1204
1205 closeSession(session);
1206 }
1207 }
1208
1209 return list;
1210 }
1211
1212
1218 public void removeByEntryId(long entryId) throws SystemException {
1219 for (AnnouncementsFlag announcementsFlag : findByEntryId(entryId)) {
1220 remove(announcementsFlag);
1221 }
1222 }
1223
1224
1233 public AnnouncementsFlag removeByU_E_V(long userId, long entryId, int value)
1234 throws NoSuchFlagException, SystemException {
1235 AnnouncementsFlag announcementsFlag = findByU_E_V(userId, entryId, value);
1236
1237 return remove(announcementsFlag);
1238 }
1239
1240
1245 public void removeAll() throws SystemException {
1246 for (AnnouncementsFlag announcementsFlag : findAll()) {
1247 remove(announcementsFlag);
1248 }
1249 }
1250
1251
1258 public int countByEntryId(long entryId) throws SystemException {
1259 Object[] finderArgs = new Object[] { entryId };
1260
1261 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ENTRYID,
1262 finderArgs, this);
1263
1264 if (count == null) {
1265 StringBundler query = new StringBundler(2);
1266
1267 query.append(_SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE);
1268
1269 query.append(_FINDER_COLUMN_ENTRYID_ENTRYID_2);
1270
1271 String sql = query.toString();
1272
1273 Session session = null;
1274
1275 try {
1276 session = openSession();
1277
1278 Query q = session.createQuery(sql);
1279
1280 QueryPos qPos = QueryPos.getInstance(q);
1281
1282 qPos.add(entryId);
1283
1284 count = (Long)q.uniqueResult();
1285 }
1286 catch (Exception e) {
1287 throw processException(e);
1288 }
1289 finally {
1290 if (count == null) {
1291 count = Long.valueOf(0);
1292 }
1293
1294 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ENTRYID,
1295 finderArgs, count);
1296
1297 closeSession(session);
1298 }
1299 }
1300
1301 return count.intValue();
1302 }
1303
1304
1313 public int countByU_E_V(long userId, long entryId, int value)
1314 throws SystemException {
1315 Object[] finderArgs = new Object[] { userId, entryId, value };
1316
1317 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_E_V,
1318 finderArgs, this);
1319
1320 if (count == null) {
1321 StringBundler query = new StringBundler(4);
1322
1323 query.append(_SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE);
1324
1325 query.append(_FINDER_COLUMN_U_E_V_USERID_2);
1326
1327 query.append(_FINDER_COLUMN_U_E_V_ENTRYID_2);
1328
1329 query.append(_FINDER_COLUMN_U_E_V_VALUE_2);
1330
1331 String sql = query.toString();
1332
1333 Session session = null;
1334
1335 try {
1336 session = openSession();
1337
1338 Query q = session.createQuery(sql);
1339
1340 QueryPos qPos = QueryPos.getInstance(q);
1341
1342 qPos.add(userId);
1343
1344 qPos.add(entryId);
1345
1346 qPos.add(value);
1347
1348 count = (Long)q.uniqueResult();
1349 }
1350 catch (Exception e) {
1351 throw processException(e);
1352 }
1353 finally {
1354 if (count == null) {
1355 count = Long.valueOf(0);
1356 }
1357
1358 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_E_V,
1359 finderArgs, count);
1360
1361 closeSession(session);
1362 }
1363 }
1364
1365 return count.intValue();
1366 }
1367
1368
1374 public int countAll() throws SystemException {
1375 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1376 FINDER_ARGS_EMPTY, this);
1377
1378 if (count == null) {
1379 Session session = null;
1380
1381 try {
1382 session = openSession();
1383
1384 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSFLAG);
1385
1386 count = (Long)q.uniqueResult();
1387 }
1388 catch (Exception e) {
1389 throw processException(e);
1390 }
1391 finally {
1392 if (count == null) {
1393 count = Long.valueOf(0);
1394 }
1395
1396 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1397 FINDER_ARGS_EMPTY, count);
1398
1399 closeSession(session);
1400 }
1401 }
1402
1403 return count.intValue();
1404 }
1405
1406
1409 public void afterPropertiesSet() {
1410 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1411 com.liferay.portal.util.PropsUtil.get(
1412 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsFlag")));
1413
1414 if (listenerClassNames.length > 0) {
1415 try {
1416 List<ModelListener<AnnouncementsFlag>> listenersList = new ArrayList<ModelListener<AnnouncementsFlag>>();
1417
1418 for (String listenerClassName : listenerClassNames) {
1419 Class<?> clazz = getClass();
1420
1421 listenersList.add((ModelListener<AnnouncementsFlag>)InstanceFactory.newInstance(
1422 clazz.getClassLoader(), listenerClassName));
1423 }
1424
1425 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1426 }
1427 catch (Exception e) {
1428 _log.error(e);
1429 }
1430 }
1431 }
1432
1433 public void destroy() {
1434 EntityCacheUtil.removeCache(AnnouncementsFlagImpl.class.getName());
1435 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1436 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1437 }
1438
1439 @BeanReference(type = AnnouncementsDeliveryPersistence.class)
1440 protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1441 @BeanReference(type = AnnouncementsEntryPersistence.class)
1442 protected AnnouncementsEntryPersistence announcementsEntryPersistence;
1443 @BeanReference(type = AnnouncementsFlagPersistence.class)
1444 protected AnnouncementsFlagPersistence announcementsFlagPersistence;
1445 @BeanReference(type = ResourcePersistence.class)
1446 protected ResourcePersistence resourcePersistence;
1447 @BeanReference(type = UserPersistence.class)
1448 protected UserPersistence userPersistence;
1449 private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag";
1450 private static final String _SQL_SELECT_ANNOUNCEMENTSFLAG_WHERE = "SELECT announcementsFlag FROM AnnouncementsFlag announcementsFlag WHERE ";
1451 private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag";
1452 private static final String _SQL_COUNT_ANNOUNCEMENTSFLAG_WHERE = "SELECT COUNT(announcementsFlag) FROM AnnouncementsFlag announcementsFlag WHERE ";
1453 private static final String _FINDER_COLUMN_ENTRYID_ENTRYID_2 = "announcementsFlag.entryId = ?";
1454 private static final String _FINDER_COLUMN_U_E_V_USERID_2 = "announcementsFlag.userId = ? AND ";
1455 private static final String _FINDER_COLUMN_U_E_V_ENTRYID_2 = "announcementsFlag.entryId = ? AND ";
1456 private static final String _FINDER_COLUMN_U_E_V_VALUE_2 = "announcementsFlag.value = ?";
1457 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsFlag.";
1458 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsFlag exists with the primary key ";
1459 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsFlag exists with the key {";
1460 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1461 private static Log _log = LogFactoryUtil.getLog(AnnouncementsFlagPersistenceImpl.class);
1462 private static AnnouncementsFlag _nullAnnouncementsFlag = new AnnouncementsFlagImpl() {
1463 @Override
1464 public Object clone() {
1465 return this;
1466 }
1467
1468 @Override
1469 public CacheModel<AnnouncementsFlag> toCacheModel() {
1470 return _nullAnnouncementsFlagCacheModel;
1471 }
1472 };
1473
1474 private static CacheModel<AnnouncementsFlag> _nullAnnouncementsFlagCacheModel =
1475 new CacheModel<AnnouncementsFlag>() {
1476 public AnnouncementsFlag toEntityModel() {
1477 return _nullAnnouncementsFlag;
1478 }
1479 };
1480 }