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