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