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