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