1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.bean.InitializingBean;
27  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
28  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
29  import com.liferay.portal.kernel.dao.orm.Query;
30  import com.liferay.portal.kernel.dao.orm.QueryPos;
31  import com.liferay.portal.kernel.dao.orm.QueryUtil;
32  import com.liferay.portal.kernel.dao.orm.Session;
33  import com.liferay.portal.kernel.util.GetterUtil;
34  import com.liferay.portal.kernel.util.ListUtil;
35  import com.liferay.portal.kernel.util.OrderByComparator;
36  import com.liferay.portal.kernel.util.StringPool;
37  import com.liferay.portal.kernel.util.StringUtil;
38  import com.liferay.portal.kernel.util.Validator;
39  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
40  import com.liferay.portal.model.ModelListener;
41  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
42  
43  import com.liferay.portlet.announcements.NoSuchEntryException;
44  import com.liferay.portlet.announcements.model.AnnouncementsEntry;
45  import com.liferay.portlet.announcements.model.impl.AnnouncementsEntryImpl;
46  import com.liferay.portlet.announcements.model.impl.AnnouncementsEntryModelImpl;
47  
48  import org.apache.commons.logging.Log;
49  import org.apache.commons.logging.LogFactory;
50  
51  import java.util.ArrayList;
52  import java.util.Collections;
53  import java.util.Iterator;
54  import java.util.List;
55  
56  /**
57   * <a href="AnnouncementsEntryPersistenceImpl.java.html"><b><i>View Source</i></b></a>
58   *
59   * @author Brian Wing Shun Chan
60   *
61   */
62  public class AnnouncementsEntryPersistenceImpl extends BasePersistenceImpl
63      implements AnnouncementsEntryPersistence, InitializingBean {
64      public AnnouncementsEntry create(long entryId) {
65          AnnouncementsEntry announcementsEntry = new AnnouncementsEntryImpl();
66  
67          announcementsEntry.setNew(true);
68          announcementsEntry.setPrimaryKey(entryId);
69  
70          String uuid = PortalUUIDUtil.generate();
71  
72          announcementsEntry.setUuid(uuid);
73  
74          return announcementsEntry;
75      }
76  
77      public AnnouncementsEntry remove(long entryId)
78          throws NoSuchEntryException, SystemException {
79          Session session = null;
80  
81          try {
82              session = openSession();
83  
84              AnnouncementsEntry announcementsEntry = (AnnouncementsEntry)session.get(AnnouncementsEntryImpl.class,
85                      new Long(entryId));
86  
87              if (announcementsEntry == null) {
88                  if (_log.isWarnEnabled()) {
89                      _log.warn(
90                          "No AnnouncementsEntry exists with the primary key " +
91                          entryId);
92                  }
93  
94                  throw new NoSuchEntryException(
95                      "No AnnouncementsEntry exists with the primary key " +
96                      entryId);
97              }
98  
99              return remove(announcementsEntry);
100         }
101         catch (NoSuchEntryException nsee) {
102             throw nsee;
103         }
104         catch (Exception e) {
105             throw processException(e);
106         }
107         finally {
108             closeSession(session);
109         }
110     }
111 
112     public AnnouncementsEntry remove(AnnouncementsEntry announcementsEntry)
113         throws SystemException {
114         if (_listeners.length > 0) {
115             for (ModelListener listener : _listeners) {
116                 listener.onBeforeRemove(announcementsEntry);
117             }
118         }
119 
120         announcementsEntry = removeImpl(announcementsEntry);
121 
122         if (_listeners.length > 0) {
123             for (ModelListener listener : _listeners) {
124                 listener.onAfterRemove(announcementsEntry);
125             }
126         }
127 
128         return announcementsEntry;
129     }
130 
131     protected AnnouncementsEntry removeImpl(
132         AnnouncementsEntry announcementsEntry) throws SystemException {
133         Session session = null;
134 
135         try {
136             session = openSession();
137 
138             session.delete(announcementsEntry);
139 
140             session.flush();
141 
142             return announcementsEntry;
143         }
144         catch (Exception e) {
145             throw processException(e);
146         }
147         finally {
148             closeSession(session);
149 
150             FinderCacheUtil.clearCache(AnnouncementsEntry.class.getName());
151         }
152     }
153 
154     /**
155      * @deprecated Use <code>update(AnnouncementsEntry announcementsEntry, boolean merge)</code>.
156      */
157     public AnnouncementsEntry update(AnnouncementsEntry announcementsEntry)
158         throws SystemException {
159         if (_log.isWarnEnabled()) {
160             _log.warn(
161                 "Using the deprecated update(AnnouncementsEntry announcementsEntry) method. Use update(AnnouncementsEntry announcementsEntry, boolean merge) instead.");
162         }
163 
164         return update(announcementsEntry, false);
165     }
166 
167     /**
168      * Add, update, or merge, the entity. This method also calls the model
169      * listeners to trigger the proper events associated with adding, deleting,
170      * or updating an entity.
171      *
172      * @param        announcementsEntry the entity to add, update, or merge
173      * @param        merge boolean value for whether to merge the entity. The
174      *                default value is false. Setting merge to true is more
175      *                expensive and should only be true when announcementsEntry is
176      *                transient. See LEP-5473 for a detailed discussion of this
177      *                method.
178      * @return        true if the portlet can be displayed via Ajax
179      */
180     public AnnouncementsEntry update(AnnouncementsEntry announcementsEntry,
181         boolean merge) throws SystemException {
182         boolean isNew = announcementsEntry.isNew();
183 
184         if (_listeners.length > 0) {
185             for (ModelListener listener : _listeners) {
186                 if (isNew) {
187                     listener.onBeforeCreate(announcementsEntry);
188                 }
189                 else {
190                     listener.onBeforeUpdate(announcementsEntry);
191                 }
192             }
193         }
194 
195         announcementsEntry = updateImpl(announcementsEntry, merge);
196 
197         if (_listeners.length > 0) {
198             for (ModelListener listener : _listeners) {
199                 if (isNew) {
200                     listener.onAfterCreate(announcementsEntry);
201                 }
202                 else {
203                     listener.onAfterUpdate(announcementsEntry);
204                 }
205             }
206         }
207 
208         return announcementsEntry;
209     }
210 
211     public AnnouncementsEntry updateImpl(
212         com.liferay.portlet.announcements.model.AnnouncementsEntry announcementsEntry,
213         boolean merge) throws SystemException {
214         if (Validator.isNull(announcementsEntry.getUuid())) {
215             String uuid = PortalUUIDUtil.generate();
216 
217             announcementsEntry.setUuid(uuid);
218         }
219 
220         Session session = null;
221 
222         try {
223             session = openSession();
224 
225             if (merge) {
226                 session.merge(announcementsEntry);
227             }
228             else {
229                 if (announcementsEntry.isNew()) {
230                     session.save(announcementsEntry);
231                 }
232             }
233 
234             session.flush();
235 
236             announcementsEntry.setNew(false);
237 
238             return announcementsEntry;
239         }
240         catch (Exception e) {
241             throw processException(e);
242         }
243         finally {
244             closeSession(session);
245 
246             FinderCacheUtil.clearCache(AnnouncementsEntry.class.getName());
247         }
248     }
249 
250     public AnnouncementsEntry findByPrimaryKey(long entryId)
251         throws NoSuchEntryException, SystemException {
252         AnnouncementsEntry announcementsEntry = fetchByPrimaryKey(entryId);
253 
254         if (announcementsEntry == null) {
255             if (_log.isWarnEnabled()) {
256                 _log.warn("No AnnouncementsEntry exists with the primary key " +
257                     entryId);
258             }
259 
260             throw new NoSuchEntryException(
261                 "No AnnouncementsEntry exists with the primary key " + entryId);
262         }
263 
264         return announcementsEntry;
265     }
266 
267     public AnnouncementsEntry fetchByPrimaryKey(long entryId)
268         throws SystemException {
269         Session session = null;
270 
271         try {
272             session = openSession();
273 
274             return (AnnouncementsEntry)session.get(AnnouncementsEntryImpl.class,
275                 new Long(entryId));
276         }
277         catch (Exception e) {
278             throw processException(e);
279         }
280         finally {
281             closeSession(session);
282         }
283     }
284 
285     public List<AnnouncementsEntry> findByUuid(String uuid)
286         throws SystemException {
287         boolean finderClassNameCacheEnabled = AnnouncementsEntryModelImpl.CACHE_ENABLED;
288         String finderClassName = AnnouncementsEntry.class.getName();
289         String finderMethodName = "findByUuid";
290         String[] finderParams = new String[] { String.class.getName() };
291         Object[] finderArgs = new Object[] { uuid };
292 
293         Object result = null;
294 
295         if (finderClassNameCacheEnabled) {
296             result = FinderCacheUtil.getResult(finderClassName,
297                     finderMethodName, finderParams, finderArgs, this);
298         }
299 
300         if (result == null) {
301             Session session = null;
302 
303             try {
304                 session = openSession();
305 
306                 StringBuilder query = new StringBuilder();
307 
308                 query.append(
309                     "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
310 
311                 if (uuid == null) {
312                     query.append("uuid_ IS NULL");
313                 }
314                 else {
315                     query.append("uuid_ = ?");
316                 }
317 
318                 query.append(" ");
319 
320                 query.append("ORDER BY ");
321 
322                 query.append("priority ASC, ");
323                 query.append("modifiedDate ASC");
324 
325                 Query q = session.createQuery(query.toString());
326 
327                 QueryPos qPos = QueryPos.getInstance(q);
328 
329                 if (uuid != null) {
330                     qPos.add(uuid);
331                 }
332 
333                 List<AnnouncementsEntry> list = q.list();
334 
335                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
336                     finderClassName, finderMethodName, finderParams,
337                     finderArgs, list);
338 
339                 return list;
340             }
341             catch (Exception e) {
342                 throw processException(e);
343             }
344             finally {
345                 closeSession(session);
346             }
347         }
348         else {
349             return (List<AnnouncementsEntry>)result;
350         }
351     }
352 
353     public List<AnnouncementsEntry> findByUuid(String uuid, int start, int end)
354         throws SystemException {
355         return findByUuid(uuid, start, end, null);
356     }
357 
358     public List<AnnouncementsEntry> findByUuid(String uuid, int start, int end,
359         OrderByComparator obc) throws SystemException {
360         boolean finderClassNameCacheEnabled = AnnouncementsEntryModelImpl.CACHE_ENABLED;
361         String finderClassName = AnnouncementsEntry.class.getName();
362         String finderMethodName = "findByUuid";
363         String[] finderParams = new String[] {
364                 String.class.getName(),
365                 
366                 "java.lang.Integer", "java.lang.Integer",
367                 "com.liferay.portal.kernel.util.OrderByComparator"
368             };
369         Object[] finderArgs = new Object[] {
370                 uuid,
371                 
372                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
373             };
374 
375         Object result = null;
376 
377         if (finderClassNameCacheEnabled) {
378             result = FinderCacheUtil.getResult(finderClassName,
379                     finderMethodName, finderParams, finderArgs, this);
380         }
381 
382         if (result == null) {
383             Session session = null;
384 
385             try {
386                 session = openSession();
387 
388                 StringBuilder query = new StringBuilder();
389 
390                 query.append(
391                     "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
392 
393                 if (uuid == null) {
394                     query.append("uuid_ IS NULL");
395                 }
396                 else {
397                     query.append("uuid_ = ?");
398                 }
399 
400                 query.append(" ");
401 
402                 if (obc != null) {
403                     query.append("ORDER BY ");
404                     query.append(obc.getOrderBy());
405                 }
406 
407                 else {
408                     query.append("ORDER BY ");
409 
410                     query.append("priority ASC, ");
411                     query.append("modifiedDate ASC");
412                 }
413 
414                 Query q = session.createQuery(query.toString());
415 
416                 QueryPos qPos = QueryPos.getInstance(q);
417 
418                 if (uuid != null) {
419                     qPos.add(uuid);
420                 }
421 
422                 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)QueryUtil.list(q,
423                         getDialect(), start, end);
424 
425                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
426                     finderClassName, finderMethodName, finderParams,
427                     finderArgs, list);
428 
429                 return list;
430             }
431             catch (Exception e) {
432                 throw processException(e);
433             }
434             finally {
435                 closeSession(session);
436             }
437         }
438         else {
439             return (List<AnnouncementsEntry>)result;
440         }
441     }
442 
443     public AnnouncementsEntry findByUuid_First(String uuid,
444         OrderByComparator obc) throws NoSuchEntryException, SystemException {
445         List<AnnouncementsEntry> list = findByUuid(uuid, 0, 1, obc);
446 
447         if (list.size() == 0) {
448             StringBuilder msg = new StringBuilder();
449 
450             msg.append("No AnnouncementsEntry exists with the key {");
451 
452             msg.append("uuid=" + uuid);
453 
454             msg.append(StringPool.CLOSE_CURLY_BRACE);
455 
456             throw new NoSuchEntryException(msg.toString());
457         }
458         else {
459             return list.get(0);
460         }
461     }
462 
463     public AnnouncementsEntry findByUuid_Last(String uuid, OrderByComparator obc)
464         throws NoSuchEntryException, SystemException {
465         int count = countByUuid(uuid);
466 
467         List<AnnouncementsEntry> list = findByUuid(uuid, count - 1, count, obc);
468 
469         if (list.size() == 0) {
470             StringBuilder msg = new StringBuilder();
471 
472             msg.append("No AnnouncementsEntry exists with the key {");
473 
474             msg.append("uuid=" + uuid);
475 
476             msg.append(StringPool.CLOSE_CURLY_BRACE);
477 
478             throw new NoSuchEntryException(msg.toString());
479         }
480         else {
481             return list.get(0);
482         }
483     }
484 
485     public AnnouncementsEntry[] findByUuid_PrevAndNext(long entryId,
486         String uuid, OrderByComparator obc)
487         throws NoSuchEntryException, SystemException {
488         AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
489 
490         int count = countByUuid(uuid);
491 
492         Session session = null;
493 
494         try {
495             session = openSession();
496 
497             StringBuilder query = new StringBuilder();
498 
499             query.append(
500                 "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
501 
502             if (uuid == null) {
503                 query.append("uuid_ IS NULL");
504             }
505             else {
506                 query.append("uuid_ = ?");
507             }
508 
509             query.append(" ");
510 
511             if (obc != null) {
512                 query.append("ORDER BY ");
513                 query.append(obc.getOrderBy());
514             }
515 
516             else {
517                 query.append("ORDER BY ");
518 
519                 query.append("priority ASC, ");
520                 query.append("modifiedDate ASC");
521             }
522 
523             Query q = session.createQuery(query.toString());
524 
525             QueryPos qPos = QueryPos.getInstance(q);
526 
527             if (uuid != null) {
528                 qPos.add(uuid);
529             }
530 
531             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
532                     announcementsEntry);
533 
534             AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
535 
536             array[0] = (AnnouncementsEntry)objArray[0];
537             array[1] = (AnnouncementsEntry)objArray[1];
538             array[2] = (AnnouncementsEntry)objArray[2];
539 
540             return array;
541         }
542         catch (Exception e) {
543             throw processException(e);
544         }
545         finally {
546             closeSession(session);
547         }
548     }
549 
550     public List<AnnouncementsEntry> findByUserId(long userId)
551         throws SystemException {
552         boolean finderClassNameCacheEnabled = AnnouncementsEntryModelImpl.CACHE_ENABLED;
553         String finderClassName = AnnouncementsEntry.class.getName();
554         String finderMethodName = "findByUserId";
555         String[] finderParams = new String[] { Long.class.getName() };
556         Object[] finderArgs = new Object[] { new Long(userId) };
557 
558         Object result = null;
559 
560         if (finderClassNameCacheEnabled) {
561             result = FinderCacheUtil.getResult(finderClassName,
562                     finderMethodName, finderParams, finderArgs, this);
563         }
564 
565         if (result == null) {
566             Session session = null;
567 
568             try {
569                 session = openSession();
570 
571                 StringBuilder query = new StringBuilder();
572 
573                 query.append(
574                     "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
575 
576                 query.append("userId = ?");
577 
578                 query.append(" ");
579 
580                 query.append("ORDER BY ");
581 
582                 query.append("priority ASC, ");
583                 query.append("modifiedDate ASC");
584 
585                 Query q = session.createQuery(query.toString());
586 
587                 QueryPos qPos = QueryPos.getInstance(q);
588 
589                 qPos.add(userId);
590 
591                 List<AnnouncementsEntry> list = q.list();
592 
593                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
594                     finderClassName, finderMethodName, finderParams,
595                     finderArgs, list);
596 
597                 return list;
598             }
599             catch (Exception e) {
600                 throw processException(e);
601             }
602             finally {
603                 closeSession(session);
604             }
605         }
606         else {
607             return (List<AnnouncementsEntry>)result;
608         }
609     }
610 
611     public List<AnnouncementsEntry> findByUserId(long userId, int start, int end)
612         throws SystemException {
613         return findByUserId(userId, start, end, null);
614     }
615 
616     public List<AnnouncementsEntry> findByUserId(long userId, int start,
617         int end, OrderByComparator obc) throws SystemException {
618         boolean finderClassNameCacheEnabled = AnnouncementsEntryModelImpl.CACHE_ENABLED;
619         String finderClassName = AnnouncementsEntry.class.getName();
620         String finderMethodName = "findByUserId";
621         String[] finderParams = new String[] {
622                 Long.class.getName(),
623                 
624                 "java.lang.Integer", "java.lang.Integer",
625                 "com.liferay.portal.kernel.util.OrderByComparator"
626             };
627         Object[] finderArgs = new Object[] {
628                 new Long(userId),
629                 
630                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
631             };
632 
633         Object result = null;
634 
635         if (finderClassNameCacheEnabled) {
636             result = FinderCacheUtil.getResult(finderClassName,
637                     finderMethodName, finderParams, finderArgs, this);
638         }
639 
640         if (result == null) {
641             Session session = null;
642 
643             try {
644                 session = openSession();
645 
646                 StringBuilder query = new StringBuilder();
647 
648                 query.append(
649                     "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
650 
651                 query.append("userId = ?");
652 
653                 query.append(" ");
654 
655                 if (obc != null) {
656                     query.append("ORDER BY ");
657                     query.append(obc.getOrderBy());
658                 }
659 
660                 else {
661                     query.append("ORDER BY ");
662 
663                     query.append("priority ASC, ");
664                     query.append("modifiedDate ASC");
665                 }
666 
667                 Query q = session.createQuery(query.toString());
668 
669                 QueryPos qPos = QueryPos.getInstance(q);
670 
671                 qPos.add(userId);
672 
673                 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)QueryUtil.list(q,
674                         getDialect(), start, end);
675 
676                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
677                     finderClassName, finderMethodName, finderParams,
678                     finderArgs, list);
679 
680                 return list;
681             }
682             catch (Exception e) {
683                 throw processException(e);
684             }
685             finally {
686                 closeSession(session);
687             }
688         }
689         else {
690             return (List<AnnouncementsEntry>)result;
691         }
692     }
693 
694     public AnnouncementsEntry findByUserId_First(long userId,
695         OrderByComparator obc) throws NoSuchEntryException, SystemException {
696         List<AnnouncementsEntry> list = findByUserId(userId, 0, 1, obc);
697 
698         if (list.size() == 0) {
699             StringBuilder msg = new StringBuilder();
700 
701             msg.append("No AnnouncementsEntry exists with the key {");
702 
703             msg.append("userId=" + userId);
704 
705             msg.append(StringPool.CLOSE_CURLY_BRACE);
706 
707             throw new NoSuchEntryException(msg.toString());
708         }
709         else {
710             return list.get(0);
711         }
712     }
713 
714     public AnnouncementsEntry findByUserId_Last(long userId,
715         OrderByComparator obc) throws NoSuchEntryException, SystemException {
716         int count = countByUserId(userId);
717 
718         List<AnnouncementsEntry> list = findByUserId(userId, count - 1, count,
719                 obc);
720 
721         if (list.size() == 0) {
722             StringBuilder msg = new StringBuilder();
723 
724             msg.append("No AnnouncementsEntry exists with the key {");
725 
726             msg.append("userId=" + userId);
727 
728             msg.append(StringPool.CLOSE_CURLY_BRACE);
729 
730             throw new NoSuchEntryException(msg.toString());
731         }
732         else {
733             return list.get(0);
734         }
735     }
736 
737     public AnnouncementsEntry[] findByUserId_PrevAndNext(long entryId,
738         long userId, OrderByComparator obc)
739         throws NoSuchEntryException, SystemException {
740         AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
741 
742         int count = countByUserId(userId);
743 
744         Session session = null;
745 
746         try {
747             session = openSession();
748 
749             StringBuilder query = new StringBuilder();
750 
751             query.append(
752                 "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
753 
754             query.append("userId = ?");
755 
756             query.append(" ");
757 
758             if (obc != null) {
759                 query.append("ORDER BY ");
760                 query.append(obc.getOrderBy());
761             }
762 
763             else {
764                 query.append("ORDER BY ");
765 
766                 query.append("priority ASC, ");
767                 query.append("modifiedDate ASC");
768             }
769 
770             Query q = session.createQuery(query.toString());
771 
772             QueryPos qPos = QueryPos.getInstance(q);
773 
774             qPos.add(userId);
775 
776             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
777                     announcementsEntry);
778 
779             AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
780 
781             array[0] = (AnnouncementsEntry)objArray[0];
782             array[1] = (AnnouncementsEntry)objArray[1];
783             array[2] = (AnnouncementsEntry)objArray[2];
784 
785             return array;
786         }
787         catch (Exception e) {
788             throw processException(e);
789         }
790         finally {
791             closeSession(session);
792         }
793     }
794 
795     public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK)
796         throws SystemException {
797         boolean finderClassNameCacheEnabled = AnnouncementsEntryModelImpl.CACHE_ENABLED;
798         String finderClassName = AnnouncementsEntry.class.getName();
799         String finderMethodName = "findByC_C";
800         String[] finderParams = new String[] {
801                 Long.class.getName(), Long.class.getName()
802             };
803         Object[] finderArgs = new Object[] {
804                 new Long(classNameId), new Long(classPK)
805             };
806 
807         Object result = null;
808 
809         if (finderClassNameCacheEnabled) {
810             result = FinderCacheUtil.getResult(finderClassName,
811                     finderMethodName, finderParams, finderArgs, this);
812         }
813 
814         if (result == null) {
815             Session session = null;
816 
817             try {
818                 session = openSession();
819 
820                 StringBuilder query = new StringBuilder();
821 
822                 query.append(
823                     "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
824 
825                 query.append("classNameId = ?");
826 
827                 query.append(" AND ");
828 
829                 query.append("classPK = ?");
830 
831                 query.append(" ");
832 
833                 query.append("ORDER BY ");
834 
835                 query.append("priority ASC, ");
836                 query.append("modifiedDate ASC");
837 
838                 Query q = session.createQuery(query.toString());
839 
840                 QueryPos qPos = QueryPos.getInstance(q);
841 
842                 qPos.add(classNameId);
843 
844                 qPos.add(classPK);
845 
846                 List<AnnouncementsEntry> list = q.list();
847 
848                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
849                     finderClassName, finderMethodName, finderParams,
850                     finderArgs, list);
851 
852                 return list;
853             }
854             catch (Exception e) {
855                 throw processException(e);
856             }
857             finally {
858                 closeSession(session);
859             }
860         }
861         else {
862             return (List<AnnouncementsEntry>)result;
863         }
864     }
865 
866     public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK,
867         int start, int end) throws SystemException {
868         return findByC_C(classNameId, classPK, start, end, null);
869     }
870 
871     public List<AnnouncementsEntry> findByC_C(long classNameId, long classPK,
872         int start, int end, OrderByComparator obc) throws SystemException {
873         boolean finderClassNameCacheEnabled = AnnouncementsEntryModelImpl.CACHE_ENABLED;
874         String finderClassName = AnnouncementsEntry.class.getName();
875         String finderMethodName = "findByC_C";
876         String[] finderParams = new String[] {
877                 Long.class.getName(), Long.class.getName(),
878                 
879                 "java.lang.Integer", "java.lang.Integer",
880                 "com.liferay.portal.kernel.util.OrderByComparator"
881             };
882         Object[] finderArgs = new Object[] {
883                 new Long(classNameId), new Long(classPK),
884                 
885                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
886             };
887 
888         Object result = null;
889 
890         if (finderClassNameCacheEnabled) {
891             result = FinderCacheUtil.getResult(finderClassName,
892                     finderMethodName, finderParams, finderArgs, this);
893         }
894 
895         if (result == null) {
896             Session session = null;
897 
898             try {
899                 session = openSession();
900 
901                 StringBuilder query = new StringBuilder();
902 
903                 query.append(
904                     "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
905 
906                 query.append("classNameId = ?");
907 
908                 query.append(" AND ");
909 
910                 query.append("classPK = ?");
911 
912                 query.append(" ");
913 
914                 if (obc != null) {
915                     query.append("ORDER BY ");
916                     query.append(obc.getOrderBy());
917                 }
918 
919                 else {
920                     query.append("ORDER BY ");
921 
922                     query.append("priority ASC, ");
923                     query.append("modifiedDate ASC");
924                 }
925 
926                 Query q = session.createQuery(query.toString());
927 
928                 QueryPos qPos = QueryPos.getInstance(q);
929 
930                 qPos.add(classNameId);
931 
932                 qPos.add(classPK);
933 
934                 List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)QueryUtil.list(q,
935                         getDialect(), start, end);
936 
937                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
938                     finderClassName, finderMethodName, finderParams,
939                     finderArgs, list);
940 
941                 return list;
942             }
943             catch (Exception e) {
944                 throw processException(e);
945             }
946             finally {
947                 closeSession(session);
948             }
949         }
950         else {
951             return (List<AnnouncementsEntry>)result;
952         }
953     }
954 
955     public AnnouncementsEntry findByC_C_First(long classNameId, long classPK,
956         OrderByComparator obc) throws NoSuchEntryException, SystemException {
957         List<AnnouncementsEntry> list = findByC_C(classNameId, classPK, 0, 1,
958                 obc);
959 
960         if (list.size() == 0) {
961             StringBuilder msg = new StringBuilder();
962 
963             msg.append("No AnnouncementsEntry exists with the key {");
964 
965             msg.append("classNameId=" + classNameId);
966 
967             msg.append(", ");
968             msg.append("classPK=" + classPK);
969 
970             msg.append(StringPool.CLOSE_CURLY_BRACE);
971 
972             throw new NoSuchEntryException(msg.toString());
973         }
974         else {
975             return list.get(0);
976         }
977     }
978 
979     public AnnouncementsEntry findByC_C_Last(long classNameId, long classPK,
980         OrderByComparator obc) throws NoSuchEntryException, SystemException {
981         int count = countByC_C(classNameId, classPK);
982 
983         List<AnnouncementsEntry> list = findByC_C(classNameId, classPK,
984                 count - 1, count, obc);
985 
986         if (list.size() == 0) {
987             StringBuilder msg = new StringBuilder();
988 
989             msg.append("No AnnouncementsEntry exists with the key {");
990 
991             msg.append("classNameId=" + classNameId);
992 
993             msg.append(", ");
994             msg.append("classPK=" + classPK);
995 
996             msg.append(StringPool.CLOSE_CURLY_BRACE);
997 
998             throw new NoSuchEntryException(msg.toString());
999         }
1000        else {
1001            return list.get(0);
1002        }
1003    }
1004
1005    public AnnouncementsEntry[] findByC_C_PrevAndNext(long entryId,
1006        long classNameId, long classPK, OrderByComparator obc)
1007        throws NoSuchEntryException, SystemException {
1008        AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1009
1010        int count = countByC_C(classNameId, classPK);
1011
1012        Session session = null;
1013
1014        try {
1015            session = openSession();
1016
1017            StringBuilder query = new StringBuilder();
1018
1019            query.append(
1020                "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
1021
1022            query.append("classNameId = ?");
1023
1024            query.append(" AND ");
1025
1026            query.append("classPK = ?");
1027
1028            query.append(" ");
1029
1030            if (obc != null) {
1031                query.append("ORDER BY ");
1032                query.append(obc.getOrderBy());
1033            }
1034
1035            else {
1036                query.append("ORDER BY ");
1037
1038                query.append("priority ASC, ");
1039                query.append("modifiedDate ASC");
1040            }
1041
1042            Query q = session.createQuery(query.toString());
1043
1044            QueryPos qPos = QueryPos.getInstance(q);
1045
1046            qPos.add(classNameId);
1047
1048            qPos.add(classPK);
1049
1050            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1051                    announcementsEntry);
1052
1053            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1054
1055            array[0] = (AnnouncementsEntry)objArray[0];
1056            array[1] = (AnnouncementsEntry)objArray[1];
1057            array[2] = (AnnouncementsEntry)objArray[2];
1058
1059            return array;
1060        }
1061        catch (Exception e) {
1062            throw processException(e);
1063        }
1064        finally {
1065            closeSession(session);
1066        }
1067    }
1068
1069    public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1070        boolean alert) throws SystemException {
1071        boolean finderClassNameCacheEnabled = AnnouncementsEntryModelImpl.CACHE_ENABLED;
1072        String finderClassName = AnnouncementsEntry.class.getName();
1073        String finderMethodName = "findByC_C_A";
1074        String[] finderParams = new String[] {
1075                Long.class.getName(), Long.class.getName(),
1076                Boolean.class.getName()
1077            };
1078        Object[] finderArgs = new Object[] {
1079                new Long(classNameId), new Long(classPK), Boolean.valueOf(alert)
1080            };
1081
1082        Object result = null;
1083
1084        if (finderClassNameCacheEnabled) {
1085            result = FinderCacheUtil.getResult(finderClassName,
1086                    finderMethodName, finderParams, finderArgs, this);
1087        }
1088
1089        if (result == null) {
1090            Session session = null;
1091
1092            try {
1093                session = openSession();
1094
1095                StringBuilder query = new StringBuilder();
1096
1097                query.append(
1098                    "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
1099
1100                query.append("classNameId = ?");
1101
1102                query.append(" AND ");
1103
1104                query.append("classPK = ?");
1105
1106                query.append(" AND ");
1107
1108                query.append("alert = ?");
1109
1110                query.append(" ");
1111
1112                query.append("ORDER BY ");
1113
1114                query.append("priority ASC, ");
1115                query.append("modifiedDate ASC");
1116
1117                Query q = session.createQuery(query.toString());
1118
1119                QueryPos qPos = QueryPos.getInstance(q);
1120
1121                qPos.add(classNameId);
1122
1123                qPos.add(classPK);
1124
1125                qPos.add(alert);
1126
1127                List<AnnouncementsEntry> list = q.list();
1128
1129                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1130                    finderClassName, finderMethodName, finderParams,
1131                    finderArgs, list);
1132
1133                return list;
1134            }
1135            catch (Exception e) {
1136                throw processException(e);
1137            }
1138            finally {
1139                closeSession(session);
1140            }
1141        }
1142        else {
1143            return (List<AnnouncementsEntry>)result;
1144        }
1145    }
1146
1147    public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1148        boolean alert, int start, int end) throws SystemException {
1149        return findByC_C_A(classNameId, classPK, alert, start, end, null);
1150    }
1151
1152    public List<AnnouncementsEntry> findByC_C_A(long classNameId, long classPK,
1153        boolean alert, int start, int end, OrderByComparator obc)
1154        throws SystemException {
1155        boolean finderClassNameCacheEnabled = AnnouncementsEntryModelImpl.CACHE_ENABLED;
1156        String finderClassName = AnnouncementsEntry.class.getName();
1157        String finderMethodName = "findByC_C_A";
1158        String[] finderParams = new String[] {
1159                Long.class.getName(), Long.class.getName(),
1160                Boolean.class.getName(),
1161                
1162                "java.lang.Integer", "java.lang.Integer",
1163                "com.liferay.portal.kernel.util.OrderByComparator"
1164            };
1165        Object[] finderArgs = new Object[] {
1166                new Long(classNameId), new Long(classPK), Boolean.valueOf(alert),
1167                
1168                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1169            };
1170
1171        Object result = null;
1172
1173        if (finderClassNameCacheEnabled) {
1174            result = FinderCacheUtil.getResult(finderClassName,
1175                    finderMethodName, finderParams, finderArgs, this);
1176        }
1177
1178        if (result == null) {
1179            Session session = null;
1180
1181            try {
1182                session = openSession();
1183
1184                StringBuilder query = new StringBuilder();
1185
1186                query.append(
1187                    "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
1188
1189                query.append("classNameId = ?");
1190
1191                query.append(" AND ");
1192
1193                query.append("classPK = ?");
1194
1195                query.append(" AND ");
1196
1197                query.append("alert = ?");
1198
1199                query.append(" ");
1200
1201                if (obc != null) {
1202                    query.append("ORDER BY ");
1203                    query.append(obc.getOrderBy());
1204                }
1205
1206                else {
1207                    query.append("ORDER BY ");
1208
1209                    query.append("priority ASC, ");
1210                    query.append("modifiedDate ASC");
1211                }
1212
1213                Query q = session.createQuery(query.toString());
1214
1215                QueryPos qPos = QueryPos.getInstance(q);
1216
1217                qPos.add(classNameId);
1218
1219                qPos.add(classPK);
1220
1221                qPos.add(alert);
1222
1223                List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1224                        getDialect(), start, end);
1225
1226                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1227                    finderClassName, finderMethodName, finderParams,
1228                    finderArgs, list);
1229
1230                return list;
1231            }
1232            catch (Exception e) {
1233                throw processException(e);
1234            }
1235            finally {
1236                closeSession(session);
1237            }
1238        }
1239        else {
1240            return (List<AnnouncementsEntry>)result;
1241        }
1242    }
1243
1244    public AnnouncementsEntry findByC_C_A_First(long classNameId, long classPK,
1245        boolean alert, OrderByComparator obc)
1246        throws NoSuchEntryException, SystemException {
1247        List<AnnouncementsEntry> list = findByC_C_A(classNameId, classPK,
1248                alert, 0, 1, obc);
1249
1250        if (list.size() == 0) {
1251            StringBuilder msg = new StringBuilder();
1252
1253            msg.append("No AnnouncementsEntry exists with the key {");
1254
1255            msg.append("classNameId=" + classNameId);
1256
1257            msg.append(", ");
1258            msg.append("classPK=" + classPK);
1259
1260            msg.append(", ");
1261            msg.append("alert=" + alert);
1262
1263            msg.append(StringPool.CLOSE_CURLY_BRACE);
1264
1265            throw new NoSuchEntryException(msg.toString());
1266        }
1267        else {
1268            return list.get(0);
1269        }
1270    }
1271
1272    public AnnouncementsEntry findByC_C_A_Last(long classNameId, long classPK,
1273        boolean alert, OrderByComparator obc)
1274        throws NoSuchEntryException, SystemException {
1275        int count = countByC_C_A(classNameId, classPK, alert);
1276
1277        List<AnnouncementsEntry> list = findByC_C_A(classNameId, classPK,
1278                alert, count - 1, count, obc);
1279
1280        if (list.size() == 0) {
1281            StringBuilder msg = new StringBuilder();
1282
1283            msg.append("No AnnouncementsEntry exists with the key {");
1284
1285            msg.append("classNameId=" + classNameId);
1286
1287            msg.append(", ");
1288            msg.append("classPK=" + classPK);
1289
1290            msg.append(", ");
1291            msg.append("alert=" + alert);
1292
1293            msg.append(StringPool.CLOSE_CURLY_BRACE);
1294
1295            throw new NoSuchEntryException(msg.toString());
1296        }
1297        else {
1298            return list.get(0);
1299        }
1300    }
1301
1302    public AnnouncementsEntry[] findByC_C_A_PrevAndNext(long entryId,
1303        long classNameId, long classPK, boolean alert, OrderByComparator obc)
1304        throws NoSuchEntryException, SystemException {
1305        AnnouncementsEntry announcementsEntry = findByPrimaryKey(entryId);
1306
1307        int count = countByC_C_A(classNameId, classPK, alert);
1308
1309        Session session = null;
1310
1311        try {
1312            session = openSession();
1313
1314            StringBuilder query = new StringBuilder();
1315
1316            query.append(
1317                "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
1318
1319            query.append("classNameId = ?");
1320
1321            query.append(" AND ");
1322
1323            query.append("classPK = ?");
1324
1325            query.append(" AND ");
1326
1327            query.append("alert = ?");
1328
1329            query.append(" ");
1330
1331            if (obc != null) {
1332                query.append("ORDER BY ");
1333                query.append(obc.getOrderBy());
1334            }
1335
1336            else {
1337                query.append("ORDER BY ");
1338
1339                query.append("priority ASC, ");
1340                query.append("modifiedDate ASC");
1341            }
1342
1343            Query q = session.createQuery(query.toString());
1344
1345            QueryPos qPos = QueryPos.getInstance(q);
1346
1347            qPos.add(classNameId);
1348
1349            qPos.add(classPK);
1350
1351            qPos.add(alert);
1352
1353            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1354                    announcementsEntry);
1355
1356            AnnouncementsEntry[] array = new AnnouncementsEntryImpl[3];
1357
1358            array[0] = (AnnouncementsEntry)objArray[0];
1359            array[1] = (AnnouncementsEntry)objArray[1];
1360            array[2] = (AnnouncementsEntry)objArray[2];
1361
1362            return array;
1363        }
1364        catch (Exception e) {
1365            throw processException(e);
1366        }
1367        finally {
1368            closeSession(session);
1369        }
1370    }
1371
1372    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1373        throws SystemException {
1374        Session session = null;
1375
1376        try {
1377            session = openSession();
1378
1379            dynamicQuery.compile(session);
1380
1381            return dynamicQuery.list();
1382        }
1383        catch (Exception e) {
1384            throw processException(e);
1385        }
1386        finally {
1387            closeSession(session);
1388        }
1389    }
1390
1391    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1392        int start, int end) throws SystemException {
1393        Session session = null;
1394
1395        try {
1396            session = openSession();
1397
1398            dynamicQuery.setLimit(start, end);
1399
1400            dynamicQuery.compile(session);
1401
1402            return dynamicQuery.list();
1403        }
1404        catch (Exception e) {
1405            throw processException(e);
1406        }
1407        finally {
1408            closeSession(session);
1409        }
1410    }
1411
1412    public List<AnnouncementsEntry> findAll() throws SystemException {
1413        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1414    }
1415
1416    public List<AnnouncementsEntry> findAll(int start, int end)
1417        throws SystemException {
1418        return findAll(start, end, null);
1419    }
1420
1421    public List<AnnouncementsEntry> findAll(int start, int end,
1422        OrderByComparator obc) throws SystemException {
1423        boolean finderClassNameCacheEnabled = AnnouncementsEntryModelImpl.CACHE_ENABLED;
1424        String finderClassName = AnnouncementsEntry.class.getName();
1425        String finderMethodName = "findAll";
1426        String[] finderParams = new String[] {
1427                "java.lang.Integer", "java.lang.Integer",
1428                "com.liferay.portal.kernel.util.OrderByComparator"
1429            };
1430        Object[] finderArgs = new Object[] {
1431                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1432            };
1433
1434        Object result = null;
1435
1436        if (finderClassNameCacheEnabled) {
1437            result = FinderCacheUtil.getResult(finderClassName,
1438                    finderMethodName, finderParams, finderArgs, this);
1439        }
1440
1441        if (result == null) {
1442            Session session = null;
1443
1444            try {
1445                session = openSession();
1446
1447                StringBuilder query = new StringBuilder();
1448
1449                query.append(
1450                    "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry ");
1451
1452                if (obc != null) {
1453                    query.append("ORDER BY ");
1454                    query.append(obc.getOrderBy());
1455                }
1456
1457                else {
1458                    query.append("ORDER BY ");
1459
1460                    query.append("priority ASC, ");
1461                    query.append("modifiedDate ASC");
1462                }
1463
1464                Query q = session.createQuery(query.toString());
1465
1466                List<AnnouncementsEntry> list = (List<AnnouncementsEntry>)QueryUtil.list(q,
1467                        getDialect(), start, end);
1468
1469                if (obc == null) {
1470                    Collections.sort(list);
1471                }
1472
1473                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1474                    finderClassName, finderMethodName, finderParams,
1475                    finderArgs, list);
1476
1477                return list;
1478            }
1479            catch (Exception e) {
1480                throw processException(e);
1481            }
1482            finally {
1483                closeSession(session);
1484            }
1485        }
1486        else {
1487            return (List<AnnouncementsEntry>)result;
1488        }
1489    }
1490
1491    public void removeByUuid(String uuid) throws SystemException {
1492        for (AnnouncementsEntry announcementsEntry : findByUuid(uuid)) {
1493            remove(announcementsEntry);
1494        }
1495    }
1496
1497    public void removeByUserId(long userId) throws SystemException {
1498        for (AnnouncementsEntry announcementsEntry : findByUserId(userId)) {
1499            remove(announcementsEntry);
1500        }
1501    }
1502
1503    public void removeByC_C(long classNameId, long classPK)
1504        throws SystemException {
1505        for (AnnouncementsEntry announcementsEntry : findByC_C(classNameId,
1506                classPK)) {
1507            remove(announcementsEntry);
1508        }
1509    }
1510
1511    public void removeByC_C_A(long classNameId, long classPK, boolean alert)
1512        throws SystemException {
1513        for (AnnouncementsEntry announcementsEntry : findByC_C_A(classNameId,
1514                classPK, alert)) {
1515            remove(announcementsEntry);
1516        }
1517    }
1518
1519    public void removeAll() throws SystemException {
1520        for (AnnouncementsEntry announcementsEntry : findAll()) {
1521            remove(announcementsEntry);
1522        }
1523    }
1524
1525    public int countByUuid(String uuid) throws SystemException {
1526        boolean finderClassNameCacheEnabled = AnnouncementsEntryModelImpl.CACHE_ENABLED;
1527        String finderClassName = AnnouncementsEntry.class.getName();
1528        String finderMethodName = "countByUuid";
1529        String[] finderParams = new String[] { String.class.getName() };
1530        Object[] finderArgs = new Object[] { uuid };
1531
1532        Object result = null;
1533
1534        if (finderClassNameCacheEnabled) {
1535            result = FinderCacheUtil.getResult(finderClassName,
1536                    finderMethodName, finderParams, finderArgs, this);
1537        }
1538
1539        if (result == null) {
1540            Session session = null;
1541
1542            try {
1543                session = openSession();
1544
1545                StringBuilder query = new StringBuilder();
1546
1547                query.append("SELECT COUNT(*) ");
1548                query.append(
1549                    "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
1550
1551                if (uuid == null) {
1552                    query.append("uuid_ IS NULL");
1553                }
1554                else {
1555                    query.append("uuid_ = ?");
1556                }
1557
1558                query.append(" ");
1559
1560                Query q = session.createQuery(query.toString());
1561
1562                QueryPos qPos = QueryPos.getInstance(q);
1563
1564                if (uuid != null) {
1565                    qPos.add(uuid);
1566                }
1567
1568                Long count = null;
1569
1570                Iterator<Long> itr = q.list().iterator();
1571
1572                if (itr.hasNext()) {
1573                    count = itr.next();
1574                }
1575
1576                if (count == null) {
1577                    count = new Long(0);
1578                }
1579
1580                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1581                    finderClassName, finderMethodName, finderParams,
1582                    finderArgs, count);
1583
1584                return count.intValue();
1585            }
1586            catch (Exception e) {
1587                throw processException(e);
1588            }
1589            finally {
1590                closeSession(session);
1591            }
1592        }
1593        else {
1594            return ((Long)result).intValue();
1595        }
1596    }
1597
1598    public int countByUserId(long userId) throws SystemException {
1599        boolean finderClassNameCacheEnabled = AnnouncementsEntryModelImpl.CACHE_ENABLED;
1600        String finderClassName = AnnouncementsEntry.class.getName();
1601        String finderMethodName = "countByUserId";
1602        String[] finderParams = new String[] { Long.class.getName() };
1603        Object[] finderArgs = new Object[] { new Long(userId) };
1604
1605        Object result = null;
1606
1607        if (finderClassNameCacheEnabled) {
1608            result = FinderCacheUtil.getResult(finderClassName,
1609                    finderMethodName, finderParams, finderArgs, this);
1610        }
1611
1612        if (result == null) {
1613            Session session = null;
1614
1615            try {
1616                session = openSession();
1617
1618                StringBuilder query = new StringBuilder();
1619
1620                query.append("SELECT COUNT(*) ");
1621                query.append(
1622                    "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
1623
1624                query.append("userId = ?");
1625
1626                query.append(" ");
1627
1628                Query q = session.createQuery(query.toString());
1629
1630                QueryPos qPos = QueryPos.getInstance(q);
1631
1632                qPos.add(userId);
1633
1634                Long count = null;
1635
1636                Iterator<Long> itr = q.list().iterator();
1637
1638                if (itr.hasNext()) {
1639                    count = itr.next();
1640                }
1641
1642                if (count == null) {
1643                    count = new Long(0);
1644                }
1645
1646                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1647                    finderClassName, finderMethodName, finderParams,
1648                    finderArgs, count);
1649
1650                return count.intValue();
1651            }
1652            catch (Exception e) {
1653                throw processException(e);
1654            }
1655            finally {
1656                closeSession(session);
1657            }
1658        }
1659        else {
1660            return ((Long)result).intValue();
1661        }
1662    }
1663
1664    public int countByC_C(long classNameId, long classPK)
1665        throws SystemException {
1666        boolean finderClassNameCacheEnabled = AnnouncementsEntryModelImpl.CACHE_ENABLED;
1667        String finderClassName = AnnouncementsEntry.class.getName();
1668        String finderMethodName = "countByC_C";
1669        String[] finderParams = new String[] {
1670                Long.class.getName(), Long.class.getName()
1671            };
1672        Object[] finderArgs = new Object[] {
1673                new Long(classNameId), new Long(classPK)
1674            };
1675
1676        Object result = null;
1677
1678        if (finderClassNameCacheEnabled) {
1679            result = FinderCacheUtil.getResult(finderClassName,
1680                    finderMethodName, finderParams, finderArgs, this);
1681        }
1682
1683        if (result == null) {
1684            Session session = null;
1685
1686            try {
1687                session = openSession();
1688
1689                StringBuilder query = new StringBuilder();
1690
1691                query.append("SELECT COUNT(*) ");
1692                query.append(
1693                    "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
1694
1695                query.append("classNameId = ?");
1696
1697                query.append(" AND ");
1698
1699                query.append("classPK = ?");
1700
1701                query.append(" ");
1702
1703                Query q = session.createQuery(query.toString());
1704
1705                QueryPos qPos = QueryPos.getInstance(q);
1706
1707                qPos.add(classNameId);
1708
1709                qPos.add(classPK);
1710
1711                Long count = null;
1712
1713                Iterator<Long> itr = q.list().iterator();
1714
1715                if (itr.hasNext()) {
1716                    count = itr.next();
1717                }
1718
1719                if (count == null) {
1720                    count = new Long(0);
1721                }
1722
1723                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1724                    finderClassName, finderMethodName, finderParams,
1725                    finderArgs, count);
1726
1727                return count.intValue();
1728            }
1729            catch (Exception e) {
1730                throw processException(e);
1731            }
1732            finally {
1733                closeSession(session);
1734            }
1735        }
1736        else {
1737            return ((Long)result).intValue();
1738        }
1739    }
1740
1741    public int countByC_C_A(long classNameId, long classPK, boolean alert)
1742        throws SystemException {
1743        boolean finderClassNameCacheEnabled = AnnouncementsEntryModelImpl.CACHE_ENABLED;
1744        String finderClassName = AnnouncementsEntry.class.getName();
1745        String finderMethodName = "countByC_C_A";
1746        String[] finderParams = new String[] {
1747                Long.class.getName(), Long.class.getName(),
1748                Boolean.class.getName()
1749            };
1750        Object[] finderArgs = new Object[] {
1751                new Long(classNameId), new Long(classPK), Boolean.valueOf(alert)
1752            };
1753
1754        Object result = null;
1755
1756        if (finderClassNameCacheEnabled) {
1757            result = FinderCacheUtil.getResult(finderClassName,
1758                    finderMethodName, finderParams, finderArgs, this);
1759        }
1760
1761        if (result == null) {
1762            Session session = null;
1763
1764            try {
1765                session = openSession();
1766
1767                StringBuilder query = new StringBuilder();
1768
1769                query.append("SELECT COUNT(*) ");
1770                query.append(
1771                    "FROM com.liferay.portlet.announcements.model.AnnouncementsEntry WHERE ");
1772
1773                query.append("classNameId = ?");
1774
1775                query.append(" AND ");
1776
1777                query.append("classPK = ?");
1778
1779                query.append(" AND ");
1780
1781                query.append("alert = ?");
1782
1783                query.append(" ");
1784
1785                Query q = session.createQuery(query.toString());
1786
1787                QueryPos qPos = QueryPos.getInstance(q);
1788
1789                qPos.add(classNameId);
1790
1791                qPos.add(classPK);
1792
1793                qPos.add(alert);
1794
1795                Long count = null;
1796
1797                Iterator<Long> itr = q.list().iterator();
1798
1799                if (itr.hasNext()) {
1800                    count = itr.next();
1801                }
1802
1803                if (count == null) {
1804                    count = new Long(0);
1805                }
1806
1807                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1808                    finderClassName, finderMethodName, finderParams,
1809                    finderArgs, count);
1810
1811                return count.intValue();
1812            }
1813            catch (Exception e) {
1814                throw processException(e);
1815            }
1816            finally {
1817                closeSession(session);
1818            }
1819        }
1820        else {
1821            return ((Long)result).intValue();
1822        }
1823    }
1824
1825    public int countAll() throws SystemException {
1826        boolean finderClassNameCacheEnabled = AnnouncementsEntryModelImpl.CACHE_ENABLED;
1827        String finderClassName = AnnouncementsEntry.class.getName();
1828        String finderMethodName = "countAll";
1829        String[] finderParams = new String[] {  };
1830        Object[] finderArgs = new Object[] {  };
1831
1832        Object result = null;
1833
1834        if (finderClassNameCacheEnabled) {
1835            result = FinderCacheUtil.getResult(finderClassName,
1836                    finderMethodName, finderParams, finderArgs, this);
1837        }
1838
1839        if (result == null) {
1840            Session session = null;
1841
1842            try {
1843                session = openSession();
1844
1845                Query q = session.createQuery(
1846                        "SELECT COUNT(*) FROM com.liferay.portlet.announcements.model.AnnouncementsEntry");
1847
1848                Long count = null;
1849
1850                Iterator<Long> itr = q.list().iterator();
1851
1852                if (itr.hasNext()) {
1853                    count = itr.next();
1854                }
1855
1856                if (count == null) {
1857                    count = new Long(0);
1858                }
1859
1860                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1861                    finderClassName, finderMethodName, finderParams,
1862                    finderArgs, count);
1863
1864                return count.intValue();
1865            }
1866            catch (Exception e) {
1867                throw processException(e);
1868            }
1869            finally {
1870                closeSession(session);
1871            }
1872        }
1873        else {
1874            return ((Long)result).intValue();
1875        }
1876    }
1877
1878    public void registerListener(ModelListener listener) {
1879        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1880
1881        listeners.add(listener);
1882
1883        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1884    }
1885
1886    public void unregisterListener(ModelListener listener) {
1887        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1888
1889        listeners.remove(listener);
1890
1891        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1892    }
1893
1894    public void afterPropertiesSet() {
1895        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1896                    com.liferay.portal.util.PropsUtil.get(
1897                        "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsEntry")));
1898
1899        if (listenerClassNames.length > 0) {
1900            try {
1901                List<ModelListener> listeners = new ArrayList<ModelListener>();
1902
1903                for (String listenerClassName : listenerClassNames) {
1904                    listeners.add((ModelListener)Class.forName(
1905                            listenerClassName).newInstance());
1906                }
1907
1908                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1909            }
1910            catch (Exception e) {
1911                _log.error(e);
1912            }
1913        }
1914    }
1915
1916    private static Log _log = LogFactory.getLog(AnnouncementsEntryPersistenceImpl.class);
1917    private ModelListener[] _listeners = new ModelListener[0];
1918}