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