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