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