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